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.NoSuchLayoutException;
020    import com.liferay.portal.kernel.bean.BeanReference;
021    import com.liferay.portal.kernel.dao.orm.EntityCache;
022    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
023    import com.liferay.portal.kernel.dao.orm.FinderCache;
024    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
025    import com.liferay.portal.kernel.dao.orm.FinderPath;
026    import com.liferay.portal.kernel.dao.orm.Query;
027    import com.liferay.portal.kernel.dao.orm.QueryPos;
028    import com.liferay.portal.kernel.dao.orm.QueryUtil;
029    import com.liferay.portal.kernel.dao.orm.SQLQuery;
030    import com.liferay.portal.kernel.dao.orm.Session;
031    import com.liferay.portal.kernel.log.Log;
032    import com.liferay.portal.kernel.log.LogFactoryUtil;
033    import com.liferay.portal.kernel.util.OrderByComparator;
034    import com.liferay.portal.kernel.util.SetUtil;
035    import com.liferay.portal.kernel.util.StringBundler;
036    import com.liferay.portal.kernel.util.StringPool;
037    import com.liferay.portal.kernel.util.StringUtil;
038    import com.liferay.portal.kernel.util.Validator;
039    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
040    import com.liferay.portal.model.CacheModel;
041    import com.liferay.portal.model.Layout;
042    import com.liferay.portal.model.MVCCModel;
043    import com.liferay.portal.model.impl.LayoutImpl;
044    import com.liferay.portal.model.impl.LayoutModelImpl;
045    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
046    import com.liferay.portal.service.ServiceContext;
047    import com.liferay.portal.service.ServiceContextThreadLocal;
048    import com.liferay.portal.service.persistence.CompanyProvider;
049    import com.liferay.portal.service.persistence.LayoutPersistence;
050    
051    import java.io.Serializable;
052    
053    import java.util.Collections;
054    import java.util.Date;
055    import java.util.HashMap;
056    import java.util.HashSet;
057    import java.util.Iterator;
058    import java.util.List;
059    import java.util.Map;
060    import java.util.Set;
061    
062    /**
063     * The persistence implementation for the layout service.
064     *
065     * <p>
066     * Caching information and settings can be found in <code>portal.properties</code>
067     * </p>
068     *
069     * @author Brian Wing Shun Chan
070     * @see LayoutPersistence
071     * @see com.liferay.portal.service.persistence.LayoutUtil
072     * @generated
073     */
074    @ProviderType
075    public class LayoutPersistenceImpl extends BasePersistenceImpl<Layout>
076            implements LayoutPersistence {
077            /*
078             * NOTE FOR DEVELOPERS:
079             *
080             * Never modify or reference this class directly. Always use {@link LayoutUtil} to access the layout persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
081             */
082            public static final String FINDER_CLASS_NAME_ENTITY = LayoutImpl.class.getName();
083            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
084                    ".List1";
085            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
086                    ".List2";
087            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
088                            LayoutModelImpl.FINDER_CACHE_ENABLED, LayoutImpl.class,
089                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
090            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
091                            LayoutModelImpl.FINDER_CACHE_ENABLED, LayoutImpl.class,
092                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
093            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
094                            LayoutModelImpl.FINDER_CACHE_ENABLED, Long.class,
095                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
096            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
097                            LayoutModelImpl.FINDER_CACHE_ENABLED, LayoutImpl.class,
098                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
099                            new String[] {
100                                    String.class.getName(),
101                                    
102                            Integer.class.getName(), Integer.class.getName(),
103                                    OrderByComparator.class.getName()
104                            });
105            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
106                            LayoutModelImpl.FINDER_CACHE_ENABLED, LayoutImpl.class,
107                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
108                            new String[] { String.class.getName() },
109                            LayoutModelImpl.UUID_COLUMN_BITMASK |
110                            LayoutModelImpl.PARENTLAYOUTID_COLUMN_BITMASK |
111                            LayoutModelImpl.PRIORITY_COLUMN_BITMASK);
112            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
113                            LayoutModelImpl.FINDER_CACHE_ENABLED, Long.class,
114                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
115                            new String[] { String.class.getName() });
116    
117            /**
118             * Returns all the layouts where uuid = &#63;.
119             *
120             * @param uuid the uuid
121             * @return the matching layouts
122             */
123            @Override
124            public List<Layout> findByUuid(String uuid) {
125                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
126            }
127    
128            /**
129             * Returns a range of all the layouts where uuid = &#63;.
130             *
131             * <p>
132             * 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 LayoutModelImpl}. 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.
133             * </p>
134             *
135             * @param uuid the uuid
136             * @param start the lower bound of the range of layouts
137             * @param end the upper bound of the range of layouts (not inclusive)
138             * @return the range of matching layouts
139             */
140            @Override
141            public List<Layout> findByUuid(String uuid, int start, int end) {
142                    return findByUuid(uuid, start, end, null);
143            }
144    
145            /**
146             * Returns an ordered range of all the layouts where uuid = &#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 LayoutModelImpl}. 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 uuid the uuid
153             * @param start the lower bound of the range of layouts
154             * @param end the upper bound of the range of layouts (not inclusive)
155             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
156             * @return the ordered range of matching layouts
157             */
158            @Override
159            public List<Layout> findByUuid(String uuid, int start, int end,
160                    OrderByComparator<Layout> orderByComparator) {
161                    return findByUuid(uuid, start, end, orderByComparator, true);
162            }
163    
164            /**
165             * Returns an ordered range of all the layouts where uuid = &#63;.
166             *
167             * <p>
168             * 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 LayoutModelImpl}. 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.
169             * </p>
170             *
171             * @param uuid the uuid
172             * @param start the lower bound of the range of layouts
173             * @param end the upper bound of the range of layouts (not inclusive)
174             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
175             * @param retrieveFromCache whether to retrieve from the finder cache
176             * @return the ordered range of matching layouts
177             */
178            @Override
179            public List<Layout> findByUuid(String uuid, int start, int end,
180                    OrderByComparator<Layout> orderByComparator, boolean retrieveFromCache) {
181                    boolean pagination = true;
182                    FinderPath finderPath = null;
183                    Object[] finderArgs = null;
184    
185                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
186                                    (orderByComparator == null)) {
187                            pagination = false;
188                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
189                            finderArgs = new Object[] { uuid };
190                    }
191                    else {
192                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
193                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
194                    }
195    
196                    List<Layout> list = null;
197    
198                    if (retrieveFromCache) {
199                            list = (List<Layout>)finderCache.getResult(finderPath, finderArgs,
200                                            this);
201    
202                            if ((list != null) && !list.isEmpty()) {
203                                    for (Layout layout : list) {
204                                            if (!Validator.equals(uuid, layout.getUuid())) {
205                                                    list = null;
206    
207                                                    break;
208                                            }
209                                    }
210                            }
211                    }
212    
213                    if (list == null) {
214                            StringBundler query = null;
215    
216                            if (orderByComparator != null) {
217                                    query = new StringBundler(3 +
218                                                    (orderByComparator.getOrderByFields().length * 3));
219                            }
220                            else {
221                                    query = new StringBundler(3);
222                            }
223    
224                            query.append(_SQL_SELECT_LAYOUT_WHERE);
225    
226                            boolean bindUuid = false;
227    
228                            if (uuid == null) {
229                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
230                            }
231                            else if (uuid.equals(StringPool.BLANK)) {
232                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
233                            }
234                            else {
235                                    bindUuid = true;
236    
237                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
238                            }
239    
240                            if (orderByComparator != null) {
241                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
242                                            orderByComparator);
243                            }
244                            else
245                             if (pagination) {
246                                    query.append(LayoutModelImpl.ORDER_BY_JPQL);
247                            }
248    
249                            String sql = query.toString();
250    
251                            Session session = null;
252    
253                            try {
254                                    session = openSession();
255    
256                                    Query q = session.createQuery(sql);
257    
258                                    QueryPos qPos = QueryPos.getInstance(q);
259    
260                                    if (bindUuid) {
261                                            qPos.add(uuid);
262                                    }
263    
264                                    if (!pagination) {
265                                            list = (List<Layout>)QueryUtil.list(q, getDialect(), start,
266                                                            end, false);
267    
268                                            Collections.sort(list);
269    
270                                            list = Collections.unmodifiableList(list);
271                                    }
272                                    else {
273                                            list = (List<Layout>)QueryUtil.list(q, getDialect(), start,
274                                                            end);
275                                    }
276    
277                                    cacheResult(list);
278    
279                                    finderCache.putResult(finderPath, finderArgs, list);
280                            }
281                            catch (Exception e) {
282                                    finderCache.removeResult(finderPath, finderArgs);
283    
284                                    throw processException(e);
285                            }
286                            finally {
287                                    closeSession(session);
288                            }
289                    }
290    
291                    return list;
292            }
293    
294            /**
295             * Returns the first layout in the ordered set where uuid = &#63;.
296             *
297             * @param uuid the uuid
298             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
299             * @return the first matching layout
300             * @throws NoSuchLayoutException if a matching layout could not be found
301             */
302            @Override
303            public Layout findByUuid_First(String uuid,
304                    OrderByComparator<Layout> orderByComparator)
305                    throws NoSuchLayoutException {
306                    Layout layout = fetchByUuid_First(uuid, orderByComparator);
307    
308                    if (layout != null) {
309                            return layout;
310                    }
311    
312                    StringBundler msg = new StringBundler(4);
313    
314                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
315    
316                    msg.append("uuid=");
317                    msg.append(uuid);
318    
319                    msg.append(StringPool.CLOSE_CURLY_BRACE);
320    
321                    throw new NoSuchLayoutException(msg.toString());
322            }
323    
324            /**
325             * Returns the first layout in the ordered set where uuid = &#63;.
326             *
327             * @param uuid the uuid
328             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
329             * @return the first matching layout, or <code>null</code> if a matching layout could not be found
330             */
331            @Override
332            public Layout fetchByUuid_First(String uuid,
333                    OrderByComparator<Layout> orderByComparator) {
334                    List<Layout> list = findByUuid(uuid, 0, 1, orderByComparator);
335    
336                    if (!list.isEmpty()) {
337                            return list.get(0);
338                    }
339    
340                    return null;
341            }
342    
343            /**
344             * Returns the last layout in the ordered set where uuid = &#63;.
345             *
346             * @param uuid the uuid
347             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
348             * @return the last matching layout
349             * @throws NoSuchLayoutException if a matching layout could not be found
350             */
351            @Override
352            public Layout findByUuid_Last(String uuid,
353                    OrderByComparator<Layout> orderByComparator)
354                    throws NoSuchLayoutException {
355                    Layout layout = fetchByUuid_Last(uuid, orderByComparator);
356    
357                    if (layout != null) {
358                            return layout;
359                    }
360    
361                    StringBundler msg = new StringBundler(4);
362    
363                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
364    
365                    msg.append("uuid=");
366                    msg.append(uuid);
367    
368                    msg.append(StringPool.CLOSE_CURLY_BRACE);
369    
370                    throw new NoSuchLayoutException(msg.toString());
371            }
372    
373            /**
374             * Returns the last layout in the ordered set where uuid = &#63;.
375             *
376             * @param uuid the uuid
377             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
378             * @return the last matching layout, or <code>null</code> if a matching layout could not be found
379             */
380            @Override
381            public Layout fetchByUuid_Last(String uuid,
382                    OrderByComparator<Layout> orderByComparator) {
383                    int count = countByUuid(uuid);
384    
385                    if (count == 0) {
386                            return null;
387                    }
388    
389                    List<Layout> list = findByUuid(uuid, count - 1, count, orderByComparator);
390    
391                    if (!list.isEmpty()) {
392                            return list.get(0);
393                    }
394    
395                    return null;
396            }
397    
398            /**
399             * Returns the layouts before and after the current layout in the ordered set where uuid = &#63;.
400             *
401             * @param plid the primary key of the current layout
402             * @param uuid the uuid
403             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
404             * @return the previous, current, and next layout
405             * @throws NoSuchLayoutException if a layout with the primary key could not be found
406             */
407            @Override
408            public Layout[] findByUuid_PrevAndNext(long plid, String uuid,
409                    OrderByComparator<Layout> orderByComparator)
410                    throws NoSuchLayoutException {
411                    Layout layout = findByPrimaryKey(plid);
412    
413                    Session session = null;
414    
415                    try {
416                            session = openSession();
417    
418                            Layout[] array = new LayoutImpl[3];
419    
420                            array[0] = getByUuid_PrevAndNext(session, layout, uuid,
421                                            orderByComparator, true);
422    
423                            array[1] = layout;
424    
425                            array[2] = getByUuid_PrevAndNext(session, layout, uuid,
426                                            orderByComparator, false);
427    
428                            return array;
429                    }
430                    catch (Exception e) {
431                            throw processException(e);
432                    }
433                    finally {
434                            closeSession(session);
435                    }
436            }
437    
438            protected Layout getByUuid_PrevAndNext(Session session, Layout layout,
439                    String uuid, OrderByComparator<Layout> orderByComparator,
440                    boolean previous) {
441                    StringBundler query = null;
442    
443                    if (orderByComparator != null) {
444                            query = new StringBundler(6 +
445                                            (orderByComparator.getOrderByFields().length * 6));
446                    }
447                    else {
448                            query = new StringBundler(3);
449                    }
450    
451                    query.append(_SQL_SELECT_LAYOUT_WHERE);
452    
453                    boolean bindUuid = false;
454    
455                    if (uuid == null) {
456                            query.append(_FINDER_COLUMN_UUID_UUID_1);
457                    }
458                    else if (uuid.equals(StringPool.BLANK)) {
459                            query.append(_FINDER_COLUMN_UUID_UUID_3);
460                    }
461                    else {
462                            bindUuid = true;
463    
464                            query.append(_FINDER_COLUMN_UUID_UUID_2);
465                    }
466    
467                    if (orderByComparator != null) {
468                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
469    
470                            if (orderByConditionFields.length > 0) {
471                                    query.append(WHERE_AND);
472                            }
473    
474                            for (int i = 0; i < orderByConditionFields.length; i++) {
475                                    query.append(_ORDER_BY_ENTITY_ALIAS);
476                                    query.append(orderByConditionFields[i]);
477    
478                                    if ((i + 1) < orderByConditionFields.length) {
479                                            if (orderByComparator.isAscending() ^ previous) {
480                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
481                                            }
482                                            else {
483                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
484                                            }
485                                    }
486                                    else {
487                                            if (orderByComparator.isAscending() ^ previous) {
488                                                    query.append(WHERE_GREATER_THAN);
489                                            }
490                                            else {
491                                                    query.append(WHERE_LESSER_THAN);
492                                            }
493                                    }
494                            }
495    
496                            query.append(ORDER_BY_CLAUSE);
497    
498                            String[] orderByFields = orderByComparator.getOrderByFields();
499    
500                            for (int i = 0; i < orderByFields.length; i++) {
501                                    query.append(_ORDER_BY_ENTITY_ALIAS);
502                                    query.append(orderByFields[i]);
503    
504                                    if ((i + 1) < orderByFields.length) {
505                                            if (orderByComparator.isAscending() ^ previous) {
506                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
507                                            }
508                                            else {
509                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
510                                            }
511                                    }
512                                    else {
513                                            if (orderByComparator.isAscending() ^ previous) {
514                                                    query.append(ORDER_BY_ASC);
515                                            }
516                                            else {
517                                                    query.append(ORDER_BY_DESC);
518                                            }
519                                    }
520                            }
521                    }
522                    else {
523                            query.append(LayoutModelImpl.ORDER_BY_JPQL);
524                    }
525    
526                    String sql = query.toString();
527    
528                    Query q = session.createQuery(sql);
529    
530                    q.setFirstResult(0);
531                    q.setMaxResults(2);
532    
533                    QueryPos qPos = QueryPos.getInstance(q);
534    
535                    if (bindUuid) {
536                            qPos.add(uuid);
537                    }
538    
539                    if (orderByComparator != null) {
540                            Object[] values = orderByComparator.getOrderByConditionValues(layout);
541    
542                            for (Object value : values) {
543                                    qPos.add(value);
544                            }
545                    }
546    
547                    List<Layout> list = q.list();
548    
549                    if (list.size() == 2) {
550                            return list.get(1);
551                    }
552                    else {
553                            return null;
554                    }
555            }
556    
557            /**
558             * Removes all the layouts where uuid = &#63; from the database.
559             *
560             * @param uuid the uuid
561             */
562            @Override
563            public void removeByUuid(String uuid) {
564                    for (Layout layout : findByUuid(uuid, QueryUtil.ALL_POS,
565                                    QueryUtil.ALL_POS, null)) {
566                            remove(layout);
567                    }
568            }
569    
570            /**
571             * Returns the number of layouts where uuid = &#63;.
572             *
573             * @param uuid the uuid
574             * @return the number of matching layouts
575             */
576            @Override
577            public int countByUuid(String uuid) {
578                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
579    
580                    Object[] finderArgs = new Object[] { uuid };
581    
582                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
583    
584                    if (count == null) {
585                            StringBundler query = new StringBundler(2);
586    
587                            query.append(_SQL_COUNT_LAYOUT_WHERE);
588    
589                            boolean bindUuid = false;
590    
591                            if (uuid == null) {
592                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
593                            }
594                            else if (uuid.equals(StringPool.BLANK)) {
595                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
596                            }
597                            else {
598                                    bindUuid = true;
599    
600                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
601                            }
602    
603                            String sql = query.toString();
604    
605                            Session session = null;
606    
607                            try {
608                                    session = openSession();
609    
610                                    Query q = session.createQuery(sql);
611    
612                                    QueryPos qPos = QueryPos.getInstance(q);
613    
614                                    if (bindUuid) {
615                                            qPos.add(uuid);
616                                    }
617    
618                                    count = (Long)q.uniqueResult();
619    
620                                    finderCache.putResult(finderPath, finderArgs, count);
621                            }
622                            catch (Exception e) {
623                                    finderCache.removeResult(finderPath, finderArgs);
624    
625                                    throw processException(e);
626                            }
627                            finally {
628                                    closeSession(session);
629                            }
630                    }
631    
632                    return count.intValue();
633            }
634    
635            private static final String _FINDER_COLUMN_UUID_UUID_1 = "layout.uuid IS NULL";
636            private static final String _FINDER_COLUMN_UUID_UUID_2 = "layout.uuid = ?";
637            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(layout.uuid IS NULL OR layout.uuid = '')";
638            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G_P = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
639                            LayoutModelImpl.FINDER_CACHE_ENABLED, LayoutImpl.class,
640                            FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G_P",
641                            new String[] {
642                                    String.class.getName(), Long.class.getName(),
643                                    Boolean.class.getName()
644                            },
645                            LayoutModelImpl.UUID_COLUMN_BITMASK |
646                            LayoutModelImpl.GROUPID_COLUMN_BITMASK |
647                            LayoutModelImpl.PRIVATELAYOUT_COLUMN_BITMASK);
648            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G_P = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
649                            LayoutModelImpl.FINDER_CACHE_ENABLED, Long.class,
650                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G_P",
651                            new String[] {
652                                    String.class.getName(), Long.class.getName(),
653                                    Boolean.class.getName()
654                            });
655    
656            /**
657             * Returns the layout where uuid = &#63; and groupId = &#63; and privateLayout = &#63; or throws a {@link NoSuchLayoutException} if it could not be found.
658             *
659             * @param uuid the uuid
660             * @param groupId the group ID
661             * @param privateLayout the private layout
662             * @return the matching layout
663             * @throws NoSuchLayoutException if a matching layout could not be found
664             */
665            @Override
666            public Layout findByUUID_G_P(String uuid, long groupId,
667                    boolean privateLayout) throws NoSuchLayoutException {
668                    Layout layout = fetchByUUID_G_P(uuid, groupId, privateLayout);
669    
670                    if (layout == null) {
671                            StringBundler msg = new StringBundler(8);
672    
673                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
674    
675                            msg.append("uuid=");
676                            msg.append(uuid);
677    
678                            msg.append(", groupId=");
679                            msg.append(groupId);
680    
681                            msg.append(", privateLayout=");
682                            msg.append(privateLayout);
683    
684                            msg.append(StringPool.CLOSE_CURLY_BRACE);
685    
686                            if (_log.isWarnEnabled()) {
687                                    _log.warn(msg.toString());
688                            }
689    
690                            throw new NoSuchLayoutException(msg.toString());
691                    }
692    
693                    return layout;
694            }
695    
696            /**
697             * Returns the layout where uuid = &#63; and groupId = &#63; and privateLayout = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
698             *
699             * @param uuid the uuid
700             * @param groupId the group ID
701             * @param privateLayout the private layout
702             * @return the matching layout, or <code>null</code> if a matching layout could not be found
703             */
704            @Override
705            public Layout fetchByUUID_G_P(String uuid, long groupId,
706                    boolean privateLayout) {
707                    return fetchByUUID_G_P(uuid, groupId, privateLayout, true);
708            }
709    
710            /**
711             * Returns the layout where uuid = &#63; and groupId = &#63; and privateLayout = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
712             *
713             * @param uuid the uuid
714             * @param groupId the group ID
715             * @param privateLayout the private layout
716             * @param retrieveFromCache whether to retrieve from the finder cache
717             * @return the matching layout, or <code>null</code> if a matching layout could not be found
718             */
719            @Override
720            public Layout fetchByUUID_G_P(String uuid, long groupId,
721                    boolean privateLayout, boolean retrieveFromCache) {
722                    Object[] finderArgs = new Object[] { uuid, groupId, privateLayout };
723    
724                    Object result = null;
725    
726                    if (retrieveFromCache) {
727                            result = finderCache.getResult(FINDER_PATH_FETCH_BY_UUID_G_P,
728                                            finderArgs, this);
729                    }
730    
731                    if (result instanceof Layout) {
732                            Layout layout = (Layout)result;
733    
734                            if (!Validator.equals(uuid, layout.getUuid()) ||
735                                            (groupId != layout.getGroupId()) ||
736                                            (privateLayout != layout.getPrivateLayout())) {
737                                    result = null;
738                            }
739                    }
740    
741                    if (result == null) {
742                            StringBundler query = new StringBundler(5);
743    
744                            query.append(_SQL_SELECT_LAYOUT_WHERE);
745    
746                            boolean bindUuid = false;
747    
748                            if (uuid == null) {
749                                    query.append(_FINDER_COLUMN_UUID_G_P_UUID_1);
750                            }
751                            else if (uuid.equals(StringPool.BLANK)) {
752                                    query.append(_FINDER_COLUMN_UUID_G_P_UUID_3);
753                            }
754                            else {
755                                    bindUuid = true;
756    
757                                    query.append(_FINDER_COLUMN_UUID_G_P_UUID_2);
758                            }
759    
760                            query.append(_FINDER_COLUMN_UUID_G_P_GROUPID_2);
761    
762                            query.append(_FINDER_COLUMN_UUID_G_P_PRIVATELAYOUT_2);
763    
764                            String sql = query.toString();
765    
766                            Session session = null;
767    
768                            try {
769                                    session = openSession();
770    
771                                    Query q = session.createQuery(sql);
772    
773                                    QueryPos qPos = QueryPos.getInstance(q);
774    
775                                    if (bindUuid) {
776                                            qPos.add(uuid);
777                                    }
778    
779                                    qPos.add(groupId);
780    
781                                    qPos.add(privateLayout);
782    
783                                    List<Layout> list = q.list();
784    
785                                    if (list.isEmpty()) {
786                                            finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G_P,
787                                                    finderArgs, list);
788                                    }
789                                    else {
790                                            Layout layout = list.get(0);
791    
792                                            result = layout;
793    
794                                            cacheResult(layout);
795    
796                                            if ((layout.getUuid() == null) ||
797                                                            !layout.getUuid().equals(uuid) ||
798                                                            (layout.getGroupId() != groupId) ||
799                                                            (layout.getPrivateLayout() != privateLayout)) {
800                                                    finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G_P,
801                                                            finderArgs, layout);
802                                            }
803                                    }
804                            }
805                            catch (Exception e) {
806                                    finderCache.removeResult(FINDER_PATH_FETCH_BY_UUID_G_P,
807                                            finderArgs);
808    
809                                    throw processException(e);
810                            }
811                            finally {
812                                    closeSession(session);
813                            }
814                    }
815    
816                    if (result instanceof List<?>) {
817                            return null;
818                    }
819                    else {
820                            return (Layout)result;
821                    }
822            }
823    
824            /**
825             * Removes the layout where uuid = &#63; and groupId = &#63; and privateLayout = &#63; from the database.
826             *
827             * @param uuid the uuid
828             * @param groupId the group ID
829             * @param privateLayout the private layout
830             * @return the layout that was removed
831             */
832            @Override
833            public Layout removeByUUID_G_P(String uuid, long groupId,
834                    boolean privateLayout) throws NoSuchLayoutException {
835                    Layout layout = findByUUID_G_P(uuid, groupId, privateLayout);
836    
837                    return remove(layout);
838            }
839    
840            /**
841             * Returns the number of layouts where uuid = &#63; and groupId = &#63; and privateLayout = &#63;.
842             *
843             * @param uuid the uuid
844             * @param groupId the group ID
845             * @param privateLayout the private layout
846             * @return the number of matching layouts
847             */
848            @Override
849            public int countByUUID_G_P(String uuid, long groupId, boolean privateLayout) {
850                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G_P;
851    
852                    Object[] finderArgs = new Object[] { uuid, groupId, privateLayout };
853    
854                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
855    
856                    if (count == null) {
857                            StringBundler query = new StringBundler(4);
858    
859                            query.append(_SQL_COUNT_LAYOUT_WHERE);
860    
861                            boolean bindUuid = false;
862    
863                            if (uuid == null) {
864                                    query.append(_FINDER_COLUMN_UUID_G_P_UUID_1);
865                            }
866                            else if (uuid.equals(StringPool.BLANK)) {
867                                    query.append(_FINDER_COLUMN_UUID_G_P_UUID_3);
868                            }
869                            else {
870                                    bindUuid = true;
871    
872                                    query.append(_FINDER_COLUMN_UUID_G_P_UUID_2);
873                            }
874    
875                            query.append(_FINDER_COLUMN_UUID_G_P_GROUPID_2);
876    
877                            query.append(_FINDER_COLUMN_UUID_G_P_PRIVATELAYOUT_2);
878    
879                            String sql = query.toString();
880    
881                            Session session = null;
882    
883                            try {
884                                    session = openSession();
885    
886                                    Query q = session.createQuery(sql);
887    
888                                    QueryPos qPos = QueryPos.getInstance(q);
889    
890                                    if (bindUuid) {
891                                            qPos.add(uuid);
892                                    }
893    
894                                    qPos.add(groupId);
895    
896                                    qPos.add(privateLayout);
897    
898                                    count = (Long)q.uniqueResult();
899    
900                                    finderCache.putResult(finderPath, finderArgs, count);
901                            }
902                            catch (Exception e) {
903                                    finderCache.removeResult(finderPath, finderArgs);
904    
905                                    throw processException(e);
906                            }
907                            finally {
908                                    closeSession(session);
909                            }
910                    }
911    
912                    return count.intValue();
913            }
914    
915            private static final String _FINDER_COLUMN_UUID_G_P_UUID_1 = "layout.uuid IS NULL AND ";
916            private static final String _FINDER_COLUMN_UUID_G_P_UUID_2 = "layout.uuid = ? AND ";
917            private static final String _FINDER_COLUMN_UUID_G_P_UUID_3 = "(layout.uuid IS NULL OR layout.uuid = '') AND ";
918            private static final String _FINDER_COLUMN_UUID_G_P_GROUPID_2 = "layout.groupId = ? AND ";
919            private static final String _FINDER_COLUMN_UUID_G_P_PRIVATELAYOUT_2 = "layout.privateLayout = ?";
920            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
921                            LayoutModelImpl.FINDER_CACHE_ENABLED, LayoutImpl.class,
922                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
923                            new String[] {
924                                    String.class.getName(), Long.class.getName(),
925                                    
926                            Integer.class.getName(), Integer.class.getName(),
927                                    OrderByComparator.class.getName()
928                            });
929            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
930                    new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
931                            LayoutModelImpl.FINDER_CACHE_ENABLED, LayoutImpl.class,
932                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
933                            new String[] { String.class.getName(), Long.class.getName() },
934                            LayoutModelImpl.UUID_COLUMN_BITMASK |
935                            LayoutModelImpl.COMPANYID_COLUMN_BITMASK |
936                            LayoutModelImpl.PARENTLAYOUTID_COLUMN_BITMASK |
937                            LayoutModelImpl.PRIORITY_COLUMN_BITMASK);
938            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
939                            LayoutModelImpl.FINDER_CACHE_ENABLED, Long.class,
940                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
941                            new String[] { String.class.getName(), Long.class.getName() });
942    
943            /**
944             * Returns all the layouts where uuid = &#63; and companyId = &#63;.
945             *
946             * @param uuid the uuid
947             * @param companyId the company ID
948             * @return the matching layouts
949             */
950            @Override
951            public List<Layout> findByUuid_C(String uuid, long companyId) {
952                    return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
953                            QueryUtil.ALL_POS, null);
954            }
955    
956            /**
957             * Returns a range of all the layouts where uuid = &#63; and companyId = &#63;.
958             *
959             * <p>
960             * 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 LayoutModelImpl}. 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.
961             * </p>
962             *
963             * @param uuid the uuid
964             * @param companyId the company ID
965             * @param start the lower bound of the range of layouts
966             * @param end the upper bound of the range of layouts (not inclusive)
967             * @return the range of matching layouts
968             */
969            @Override
970            public List<Layout> findByUuid_C(String uuid, long companyId, int start,
971                    int end) {
972                    return findByUuid_C(uuid, companyId, start, end, null);
973            }
974    
975            /**
976             * Returns an ordered range of all the layouts where uuid = &#63; and companyId = &#63;.
977             *
978             * <p>
979             * 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 LayoutModelImpl}. 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.
980             * </p>
981             *
982             * @param uuid the uuid
983             * @param companyId the company ID
984             * @param start the lower bound of the range of layouts
985             * @param end the upper bound of the range of layouts (not inclusive)
986             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
987             * @return the ordered range of matching layouts
988             */
989            @Override
990            public List<Layout> findByUuid_C(String uuid, long companyId, int start,
991                    int end, OrderByComparator<Layout> orderByComparator) {
992                    return findByUuid_C(uuid, companyId, start, end, orderByComparator, true);
993            }
994    
995            /**
996             * Returns an ordered range of all the layouts where uuid = &#63; and companyId = &#63;.
997             *
998             * <p>
999             * 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 LayoutModelImpl}. 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.
1000             * </p>
1001             *
1002             * @param uuid the uuid
1003             * @param companyId the company ID
1004             * @param start the lower bound of the range of layouts
1005             * @param end the upper bound of the range of layouts (not inclusive)
1006             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1007             * @param retrieveFromCache whether to retrieve from the finder cache
1008             * @return the ordered range of matching layouts
1009             */
1010            @Override
1011            public List<Layout> findByUuid_C(String uuid, long companyId, int start,
1012                    int end, OrderByComparator<Layout> orderByComparator,
1013                    boolean retrieveFromCache) {
1014                    boolean pagination = true;
1015                    FinderPath finderPath = null;
1016                    Object[] finderArgs = null;
1017    
1018                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1019                                    (orderByComparator == null)) {
1020                            pagination = false;
1021                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
1022                            finderArgs = new Object[] { uuid, companyId };
1023                    }
1024                    else {
1025                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
1026                            finderArgs = new Object[] {
1027                                            uuid, companyId,
1028                                            
1029                                            start, end, orderByComparator
1030                                    };
1031                    }
1032    
1033                    List<Layout> list = null;
1034    
1035                    if (retrieveFromCache) {
1036                            list = (List<Layout>)finderCache.getResult(finderPath, finderArgs,
1037                                            this);
1038    
1039                            if ((list != null) && !list.isEmpty()) {
1040                                    for (Layout layout : list) {
1041                                            if (!Validator.equals(uuid, layout.getUuid()) ||
1042                                                            (companyId != layout.getCompanyId())) {
1043                                                    list = null;
1044    
1045                                                    break;
1046                                            }
1047                                    }
1048                            }
1049                    }
1050    
1051                    if (list == null) {
1052                            StringBundler query = null;
1053    
1054                            if (orderByComparator != null) {
1055                                    query = new StringBundler(4 +
1056                                                    (orderByComparator.getOrderByFields().length * 3));
1057                            }
1058                            else {
1059                                    query = new StringBundler(4);
1060                            }
1061    
1062                            query.append(_SQL_SELECT_LAYOUT_WHERE);
1063    
1064                            boolean bindUuid = false;
1065    
1066                            if (uuid == null) {
1067                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1068                            }
1069                            else if (uuid.equals(StringPool.BLANK)) {
1070                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1071                            }
1072                            else {
1073                                    bindUuid = true;
1074    
1075                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1076                            }
1077    
1078                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1079    
1080                            if (orderByComparator != null) {
1081                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1082                                            orderByComparator);
1083                            }
1084                            else
1085                             if (pagination) {
1086                                    query.append(LayoutModelImpl.ORDER_BY_JPQL);
1087                            }
1088    
1089                            String sql = query.toString();
1090    
1091                            Session session = null;
1092    
1093                            try {
1094                                    session = openSession();
1095    
1096                                    Query q = session.createQuery(sql);
1097    
1098                                    QueryPos qPos = QueryPos.getInstance(q);
1099    
1100                                    if (bindUuid) {
1101                                            qPos.add(uuid);
1102                                    }
1103    
1104                                    qPos.add(companyId);
1105    
1106                                    if (!pagination) {
1107                                            list = (List<Layout>)QueryUtil.list(q, getDialect(), start,
1108                                                            end, false);
1109    
1110                                            Collections.sort(list);
1111    
1112                                            list = Collections.unmodifiableList(list);
1113                                    }
1114                                    else {
1115                                            list = (List<Layout>)QueryUtil.list(q, getDialect(), start,
1116                                                            end);
1117                                    }
1118    
1119                                    cacheResult(list);
1120    
1121                                    finderCache.putResult(finderPath, finderArgs, list);
1122                            }
1123                            catch (Exception e) {
1124                                    finderCache.removeResult(finderPath, finderArgs);
1125    
1126                                    throw processException(e);
1127                            }
1128                            finally {
1129                                    closeSession(session);
1130                            }
1131                    }
1132    
1133                    return list;
1134            }
1135    
1136            /**
1137             * Returns the first layout in the ordered set where uuid = &#63; and companyId = &#63;.
1138             *
1139             * @param uuid the uuid
1140             * @param companyId the company ID
1141             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1142             * @return the first matching layout
1143             * @throws NoSuchLayoutException if a matching layout could not be found
1144             */
1145            @Override
1146            public Layout findByUuid_C_First(String uuid, long companyId,
1147                    OrderByComparator<Layout> orderByComparator)
1148                    throws NoSuchLayoutException {
1149                    Layout layout = fetchByUuid_C_First(uuid, companyId, orderByComparator);
1150    
1151                    if (layout != null) {
1152                            return layout;
1153                    }
1154    
1155                    StringBundler msg = new StringBundler(6);
1156    
1157                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1158    
1159                    msg.append("uuid=");
1160                    msg.append(uuid);
1161    
1162                    msg.append(", companyId=");
1163                    msg.append(companyId);
1164    
1165                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1166    
1167                    throw new NoSuchLayoutException(msg.toString());
1168            }
1169    
1170            /**
1171             * Returns the first layout in the ordered set where uuid = &#63; and companyId = &#63;.
1172             *
1173             * @param uuid the uuid
1174             * @param companyId the company ID
1175             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1176             * @return the first matching layout, or <code>null</code> if a matching layout could not be found
1177             */
1178            @Override
1179            public Layout fetchByUuid_C_First(String uuid, long companyId,
1180                    OrderByComparator<Layout> orderByComparator) {
1181                    List<Layout> list = findByUuid_C(uuid, companyId, 0, 1,
1182                                    orderByComparator);
1183    
1184                    if (!list.isEmpty()) {
1185                            return list.get(0);
1186                    }
1187    
1188                    return null;
1189            }
1190    
1191            /**
1192             * Returns the last layout in the ordered set where uuid = &#63; and companyId = &#63;.
1193             *
1194             * @param uuid the uuid
1195             * @param companyId the company ID
1196             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1197             * @return the last matching layout
1198             * @throws NoSuchLayoutException if a matching layout could not be found
1199             */
1200            @Override
1201            public Layout findByUuid_C_Last(String uuid, long companyId,
1202                    OrderByComparator<Layout> orderByComparator)
1203                    throws NoSuchLayoutException {
1204                    Layout layout = fetchByUuid_C_Last(uuid, companyId, orderByComparator);
1205    
1206                    if (layout != null) {
1207                            return layout;
1208                    }
1209    
1210                    StringBundler msg = new StringBundler(6);
1211    
1212                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1213    
1214                    msg.append("uuid=");
1215                    msg.append(uuid);
1216    
1217                    msg.append(", companyId=");
1218                    msg.append(companyId);
1219    
1220                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1221    
1222                    throw new NoSuchLayoutException(msg.toString());
1223            }
1224    
1225            /**
1226             * Returns the last layout in the ordered set where uuid = &#63; and companyId = &#63;.
1227             *
1228             * @param uuid the uuid
1229             * @param companyId the company ID
1230             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1231             * @return the last matching layout, or <code>null</code> if a matching layout could not be found
1232             */
1233            @Override
1234            public Layout fetchByUuid_C_Last(String uuid, long companyId,
1235                    OrderByComparator<Layout> orderByComparator) {
1236                    int count = countByUuid_C(uuid, companyId);
1237    
1238                    if (count == 0) {
1239                            return null;
1240                    }
1241    
1242                    List<Layout> list = findByUuid_C(uuid, companyId, count - 1, count,
1243                                    orderByComparator);
1244    
1245                    if (!list.isEmpty()) {
1246                            return list.get(0);
1247                    }
1248    
1249                    return null;
1250            }
1251    
1252            /**
1253             * Returns the layouts before and after the current layout in the ordered set where uuid = &#63; and companyId = &#63;.
1254             *
1255             * @param plid the primary key of the current layout
1256             * @param uuid the uuid
1257             * @param companyId the company ID
1258             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1259             * @return the previous, current, and next layout
1260             * @throws NoSuchLayoutException if a layout with the primary key could not be found
1261             */
1262            @Override
1263            public Layout[] findByUuid_C_PrevAndNext(long plid, String uuid,
1264                    long companyId, OrderByComparator<Layout> orderByComparator)
1265                    throws NoSuchLayoutException {
1266                    Layout layout = findByPrimaryKey(plid);
1267    
1268                    Session session = null;
1269    
1270                    try {
1271                            session = openSession();
1272    
1273                            Layout[] array = new LayoutImpl[3];
1274    
1275                            array[0] = getByUuid_C_PrevAndNext(session, layout, uuid,
1276                                            companyId, orderByComparator, true);
1277    
1278                            array[1] = layout;
1279    
1280                            array[2] = getByUuid_C_PrevAndNext(session, layout, uuid,
1281                                            companyId, orderByComparator, false);
1282    
1283                            return array;
1284                    }
1285                    catch (Exception e) {
1286                            throw processException(e);
1287                    }
1288                    finally {
1289                            closeSession(session);
1290                    }
1291            }
1292    
1293            protected Layout getByUuid_C_PrevAndNext(Session session, Layout layout,
1294                    String uuid, long companyId,
1295                    OrderByComparator<Layout> orderByComparator, boolean previous) {
1296                    StringBundler query = null;
1297    
1298                    if (orderByComparator != null) {
1299                            query = new StringBundler(6 +
1300                                            (orderByComparator.getOrderByFields().length * 6));
1301                    }
1302                    else {
1303                            query = new StringBundler(3);
1304                    }
1305    
1306                    query.append(_SQL_SELECT_LAYOUT_WHERE);
1307    
1308                    boolean bindUuid = false;
1309    
1310                    if (uuid == null) {
1311                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1312                    }
1313                    else if (uuid.equals(StringPool.BLANK)) {
1314                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1315                    }
1316                    else {
1317                            bindUuid = true;
1318    
1319                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1320                    }
1321    
1322                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1323    
1324                    if (orderByComparator != null) {
1325                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1326    
1327                            if (orderByConditionFields.length > 0) {
1328                                    query.append(WHERE_AND);
1329                            }
1330    
1331                            for (int i = 0; i < orderByConditionFields.length; i++) {
1332                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1333                                    query.append(orderByConditionFields[i]);
1334    
1335                                    if ((i + 1) < orderByConditionFields.length) {
1336                                            if (orderByComparator.isAscending() ^ previous) {
1337                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1338                                            }
1339                                            else {
1340                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1341                                            }
1342                                    }
1343                                    else {
1344                                            if (orderByComparator.isAscending() ^ previous) {
1345                                                    query.append(WHERE_GREATER_THAN);
1346                                            }
1347                                            else {
1348                                                    query.append(WHERE_LESSER_THAN);
1349                                            }
1350                                    }
1351                            }
1352    
1353                            query.append(ORDER_BY_CLAUSE);
1354    
1355                            String[] orderByFields = orderByComparator.getOrderByFields();
1356    
1357                            for (int i = 0; i < orderByFields.length; i++) {
1358                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1359                                    query.append(orderByFields[i]);
1360    
1361                                    if ((i + 1) < orderByFields.length) {
1362                                            if (orderByComparator.isAscending() ^ previous) {
1363                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1364                                            }
1365                                            else {
1366                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1367                                            }
1368                                    }
1369                                    else {
1370                                            if (orderByComparator.isAscending() ^ previous) {
1371                                                    query.append(ORDER_BY_ASC);
1372                                            }
1373                                            else {
1374                                                    query.append(ORDER_BY_DESC);
1375                                            }
1376                                    }
1377                            }
1378                    }
1379                    else {
1380                            query.append(LayoutModelImpl.ORDER_BY_JPQL);
1381                    }
1382    
1383                    String sql = query.toString();
1384    
1385                    Query q = session.createQuery(sql);
1386    
1387                    q.setFirstResult(0);
1388                    q.setMaxResults(2);
1389    
1390                    QueryPos qPos = QueryPos.getInstance(q);
1391    
1392                    if (bindUuid) {
1393                            qPos.add(uuid);
1394                    }
1395    
1396                    qPos.add(companyId);
1397    
1398                    if (orderByComparator != null) {
1399                            Object[] values = orderByComparator.getOrderByConditionValues(layout);
1400    
1401                            for (Object value : values) {
1402                                    qPos.add(value);
1403                            }
1404                    }
1405    
1406                    List<Layout> list = q.list();
1407    
1408                    if (list.size() == 2) {
1409                            return list.get(1);
1410                    }
1411                    else {
1412                            return null;
1413                    }
1414            }
1415    
1416            /**
1417             * Removes all the layouts where uuid = &#63; and companyId = &#63; from the database.
1418             *
1419             * @param uuid the uuid
1420             * @param companyId the company ID
1421             */
1422            @Override
1423            public void removeByUuid_C(String uuid, long companyId) {
1424                    for (Layout layout : findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
1425                                    QueryUtil.ALL_POS, null)) {
1426                            remove(layout);
1427                    }
1428            }
1429    
1430            /**
1431             * Returns the number of layouts where uuid = &#63; and companyId = &#63;.
1432             *
1433             * @param uuid the uuid
1434             * @param companyId the company ID
1435             * @return the number of matching layouts
1436             */
1437            @Override
1438            public int countByUuid_C(String uuid, long companyId) {
1439                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1440    
1441                    Object[] finderArgs = new Object[] { uuid, companyId };
1442    
1443                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1444    
1445                    if (count == null) {
1446                            StringBundler query = new StringBundler(3);
1447    
1448                            query.append(_SQL_COUNT_LAYOUT_WHERE);
1449    
1450                            boolean bindUuid = false;
1451    
1452                            if (uuid == null) {
1453                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1454                            }
1455                            else if (uuid.equals(StringPool.BLANK)) {
1456                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1457                            }
1458                            else {
1459                                    bindUuid = true;
1460    
1461                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1462                            }
1463    
1464                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1465    
1466                            String sql = query.toString();
1467    
1468                            Session session = null;
1469    
1470                            try {
1471                                    session = openSession();
1472    
1473                                    Query q = session.createQuery(sql);
1474    
1475                                    QueryPos qPos = QueryPos.getInstance(q);
1476    
1477                                    if (bindUuid) {
1478                                            qPos.add(uuid);
1479                                    }
1480    
1481                                    qPos.add(companyId);
1482    
1483                                    count = (Long)q.uniqueResult();
1484    
1485                                    finderCache.putResult(finderPath, finderArgs, count);
1486                            }
1487                            catch (Exception e) {
1488                                    finderCache.removeResult(finderPath, finderArgs);
1489    
1490                                    throw processException(e);
1491                            }
1492                            finally {
1493                                    closeSession(session);
1494                            }
1495                    }
1496    
1497                    return count.intValue();
1498            }
1499    
1500            private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "layout.uuid IS NULL AND ";
1501            private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "layout.uuid = ? AND ";
1502            private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(layout.uuid IS NULL OR layout.uuid = '') AND ";
1503            private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "layout.companyId = ?";
1504            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
1505                            LayoutModelImpl.FINDER_CACHE_ENABLED, LayoutImpl.class,
1506                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
1507                            new String[] {
1508                                    Long.class.getName(),
1509                                    
1510                            Integer.class.getName(), Integer.class.getName(),
1511                                    OrderByComparator.class.getName()
1512                            });
1513            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
1514                    new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
1515                            LayoutModelImpl.FINDER_CACHE_ENABLED, LayoutImpl.class,
1516                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
1517                            new String[] { Long.class.getName() },
1518                            LayoutModelImpl.GROUPID_COLUMN_BITMASK |
1519                            LayoutModelImpl.PARENTLAYOUTID_COLUMN_BITMASK |
1520                            LayoutModelImpl.PRIORITY_COLUMN_BITMASK);
1521            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
1522                            LayoutModelImpl.FINDER_CACHE_ENABLED, Long.class,
1523                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
1524                            new String[] { Long.class.getName() });
1525    
1526            /**
1527             * Returns all the layouts where groupId = &#63;.
1528             *
1529             * @param groupId the group ID
1530             * @return the matching layouts
1531             */
1532            @Override
1533            public List<Layout> findByGroupId(long groupId) {
1534                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1535            }
1536    
1537            /**
1538             * Returns a range of all the layouts where groupId = &#63;.
1539             *
1540             * <p>
1541             * 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 LayoutModelImpl}. 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.
1542             * </p>
1543             *
1544             * @param groupId the group ID
1545             * @param start the lower bound of the range of layouts
1546             * @param end the upper bound of the range of layouts (not inclusive)
1547             * @return the range of matching layouts
1548             */
1549            @Override
1550            public List<Layout> findByGroupId(long groupId, int start, int end) {
1551                    return findByGroupId(groupId, start, end, null);
1552            }
1553    
1554            /**
1555             * Returns an ordered range of all the layouts where groupId = &#63;.
1556             *
1557             * <p>
1558             * 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 LayoutModelImpl}. 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.
1559             * </p>
1560             *
1561             * @param groupId the group ID
1562             * @param start the lower bound of the range of layouts
1563             * @param end the upper bound of the range of layouts (not inclusive)
1564             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1565             * @return the ordered range of matching layouts
1566             */
1567            @Override
1568            public List<Layout> findByGroupId(long groupId, int start, int end,
1569                    OrderByComparator<Layout> orderByComparator) {
1570                    return findByGroupId(groupId, start, end, orderByComparator, true);
1571            }
1572    
1573            /**
1574             * Returns an ordered range of all the layouts where groupId = &#63;.
1575             *
1576             * <p>
1577             * 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 LayoutModelImpl}. 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.
1578             * </p>
1579             *
1580             * @param groupId the group ID
1581             * @param start the lower bound of the range of layouts
1582             * @param end the upper bound of the range of layouts (not inclusive)
1583             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1584             * @param retrieveFromCache whether to retrieve from the finder cache
1585             * @return the ordered range of matching layouts
1586             */
1587            @Override
1588            public List<Layout> findByGroupId(long groupId, int start, int end,
1589                    OrderByComparator<Layout> orderByComparator, boolean retrieveFromCache) {
1590                    boolean pagination = true;
1591                    FinderPath finderPath = null;
1592                    Object[] finderArgs = null;
1593    
1594                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1595                                    (orderByComparator == null)) {
1596                            pagination = false;
1597                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1598                            finderArgs = new Object[] { groupId };
1599                    }
1600                    else {
1601                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1602                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
1603                    }
1604    
1605                    List<Layout> list = null;
1606    
1607                    if (retrieveFromCache) {
1608                            list = (List<Layout>)finderCache.getResult(finderPath, finderArgs,
1609                                            this);
1610    
1611                            if ((list != null) && !list.isEmpty()) {
1612                                    for (Layout layout : list) {
1613                                            if ((groupId != layout.getGroupId())) {
1614                                                    list = null;
1615    
1616                                                    break;
1617                                            }
1618                                    }
1619                            }
1620                    }
1621    
1622                    if (list == null) {
1623                            StringBundler query = null;
1624    
1625                            if (orderByComparator != null) {
1626                                    query = new StringBundler(3 +
1627                                                    (orderByComparator.getOrderByFields().length * 3));
1628                            }
1629                            else {
1630                                    query = new StringBundler(3);
1631                            }
1632    
1633                            query.append(_SQL_SELECT_LAYOUT_WHERE);
1634    
1635                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1636    
1637                            if (orderByComparator != null) {
1638                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1639                                            orderByComparator);
1640                            }
1641                            else
1642                             if (pagination) {
1643                                    query.append(LayoutModelImpl.ORDER_BY_JPQL);
1644                            }
1645    
1646                            String sql = query.toString();
1647    
1648                            Session session = null;
1649    
1650                            try {
1651                                    session = openSession();
1652    
1653                                    Query q = session.createQuery(sql);
1654    
1655                                    QueryPos qPos = QueryPos.getInstance(q);
1656    
1657                                    qPos.add(groupId);
1658    
1659                                    if (!pagination) {
1660                                            list = (List<Layout>)QueryUtil.list(q, getDialect(), start,
1661                                                            end, false);
1662    
1663                                            Collections.sort(list);
1664    
1665                                            list = Collections.unmodifiableList(list);
1666                                    }
1667                                    else {
1668                                            list = (List<Layout>)QueryUtil.list(q, getDialect(), start,
1669                                                            end);
1670                                    }
1671    
1672                                    cacheResult(list);
1673    
1674                                    finderCache.putResult(finderPath, finderArgs, list);
1675                            }
1676                            catch (Exception e) {
1677                                    finderCache.removeResult(finderPath, finderArgs);
1678    
1679                                    throw processException(e);
1680                            }
1681                            finally {
1682                                    closeSession(session);
1683                            }
1684                    }
1685    
1686                    return list;
1687            }
1688    
1689            /**
1690             * Returns the first layout in the ordered set where groupId = &#63;.
1691             *
1692             * @param groupId the group ID
1693             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1694             * @return the first matching layout
1695             * @throws NoSuchLayoutException if a matching layout could not be found
1696             */
1697            @Override
1698            public Layout findByGroupId_First(long groupId,
1699                    OrderByComparator<Layout> orderByComparator)
1700                    throws NoSuchLayoutException {
1701                    Layout layout = fetchByGroupId_First(groupId, orderByComparator);
1702    
1703                    if (layout != null) {
1704                            return layout;
1705                    }
1706    
1707                    StringBundler msg = new StringBundler(4);
1708    
1709                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1710    
1711                    msg.append("groupId=");
1712                    msg.append(groupId);
1713    
1714                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1715    
1716                    throw new NoSuchLayoutException(msg.toString());
1717            }
1718    
1719            /**
1720             * Returns the first layout in the ordered set where groupId = &#63;.
1721             *
1722             * @param groupId the group ID
1723             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1724             * @return the first matching layout, or <code>null</code> if a matching layout could not be found
1725             */
1726            @Override
1727            public Layout fetchByGroupId_First(long groupId,
1728                    OrderByComparator<Layout> orderByComparator) {
1729                    List<Layout> list = findByGroupId(groupId, 0, 1, orderByComparator);
1730    
1731                    if (!list.isEmpty()) {
1732                            return list.get(0);
1733                    }
1734    
1735                    return null;
1736            }
1737    
1738            /**
1739             * Returns the last layout in the ordered set where groupId = &#63;.
1740             *
1741             * @param groupId the group ID
1742             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1743             * @return the last matching layout
1744             * @throws NoSuchLayoutException if a matching layout could not be found
1745             */
1746            @Override
1747            public Layout findByGroupId_Last(long groupId,
1748                    OrderByComparator<Layout> orderByComparator)
1749                    throws NoSuchLayoutException {
1750                    Layout layout = fetchByGroupId_Last(groupId, orderByComparator);
1751    
1752                    if (layout != null) {
1753                            return layout;
1754                    }
1755    
1756                    StringBundler msg = new StringBundler(4);
1757    
1758                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1759    
1760                    msg.append("groupId=");
1761                    msg.append(groupId);
1762    
1763                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1764    
1765                    throw new NoSuchLayoutException(msg.toString());
1766            }
1767    
1768            /**
1769             * Returns the last layout in the ordered set where groupId = &#63;.
1770             *
1771             * @param groupId the group ID
1772             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1773             * @return the last matching layout, or <code>null</code> if a matching layout could not be found
1774             */
1775            @Override
1776            public Layout fetchByGroupId_Last(long groupId,
1777                    OrderByComparator<Layout> orderByComparator) {
1778                    int count = countByGroupId(groupId);
1779    
1780                    if (count == 0) {
1781                            return null;
1782                    }
1783    
1784                    List<Layout> list = findByGroupId(groupId, count - 1, count,
1785                                    orderByComparator);
1786    
1787                    if (!list.isEmpty()) {
1788                            return list.get(0);
1789                    }
1790    
1791                    return null;
1792            }
1793    
1794            /**
1795             * Returns the layouts before and after the current layout in the ordered set where groupId = &#63;.
1796             *
1797             * @param plid the primary key of the current layout
1798             * @param groupId the group ID
1799             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1800             * @return the previous, current, and next layout
1801             * @throws NoSuchLayoutException if a layout with the primary key could not be found
1802             */
1803            @Override
1804            public Layout[] findByGroupId_PrevAndNext(long plid, long groupId,
1805                    OrderByComparator<Layout> orderByComparator)
1806                    throws NoSuchLayoutException {
1807                    Layout layout = findByPrimaryKey(plid);
1808    
1809                    Session session = null;
1810    
1811                    try {
1812                            session = openSession();
1813    
1814                            Layout[] array = new LayoutImpl[3];
1815    
1816                            array[0] = getByGroupId_PrevAndNext(session, layout, groupId,
1817                                            orderByComparator, true);
1818    
1819                            array[1] = layout;
1820    
1821                            array[2] = getByGroupId_PrevAndNext(session, layout, groupId,
1822                                            orderByComparator, false);
1823    
1824                            return array;
1825                    }
1826                    catch (Exception e) {
1827                            throw processException(e);
1828                    }
1829                    finally {
1830                            closeSession(session);
1831                    }
1832            }
1833    
1834            protected Layout getByGroupId_PrevAndNext(Session session, Layout layout,
1835                    long groupId, OrderByComparator<Layout> orderByComparator,
1836                    boolean previous) {
1837                    StringBundler query = null;
1838    
1839                    if (orderByComparator != null) {
1840                            query = new StringBundler(6 +
1841                                            (orderByComparator.getOrderByFields().length * 6));
1842                    }
1843                    else {
1844                            query = new StringBundler(3);
1845                    }
1846    
1847                    query.append(_SQL_SELECT_LAYOUT_WHERE);
1848    
1849                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1850    
1851                    if (orderByComparator != null) {
1852                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1853    
1854                            if (orderByConditionFields.length > 0) {
1855                                    query.append(WHERE_AND);
1856                            }
1857    
1858                            for (int i = 0; i < orderByConditionFields.length; i++) {
1859                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1860                                    query.append(orderByConditionFields[i]);
1861    
1862                                    if ((i + 1) < orderByConditionFields.length) {
1863                                            if (orderByComparator.isAscending() ^ previous) {
1864                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1865                                            }
1866                                            else {
1867                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1868                                            }
1869                                    }
1870                                    else {
1871                                            if (orderByComparator.isAscending() ^ previous) {
1872                                                    query.append(WHERE_GREATER_THAN);
1873                                            }
1874                                            else {
1875                                                    query.append(WHERE_LESSER_THAN);
1876                                            }
1877                                    }
1878                            }
1879    
1880                            query.append(ORDER_BY_CLAUSE);
1881    
1882                            String[] orderByFields = orderByComparator.getOrderByFields();
1883    
1884                            for (int i = 0; i < orderByFields.length; i++) {
1885                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1886                                    query.append(orderByFields[i]);
1887    
1888                                    if ((i + 1) < orderByFields.length) {
1889                                            if (orderByComparator.isAscending() ^ previous) {
1890                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1891                                            }
1892                                            else {
1893                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1894                                            }
1895                                    }
1896                                    else {
1897                                            if (orderByComparator.isAscending() ^ previous) {
1898                                                    query.append(ORDER_BY_ASC);
1899                                            }
1900                                            else {
1901                                                    query.append(ORDER_BY_DESC);
1902                                            }
1903                                    }
1904                            }
1905                    }
1906                    else {
1907                            query.append(LayoutModelImpl.ORDER_BY_JPQL);
1908                    }
1909    
1910                    String sql = query.toString();
1911    
1912                    Query q = session.createQuery(sql);
1913    
1914                    q.setFirstResult(0);
1915                    q.setMaxResults(2);
1916    
1917                    QueryPos qPos = QueryPos.getInstance(q);
1918    
1919                    qPos.add(groupId);
1920    
1921                    if (orderByComparator != null) {
1922                            Object[] values = orderByComparator.getOrderByConditionValues(layout);
1923    
1924                            for (Object value : values) {
1925                                    qPos.add(value);
1926                            }
1927                    }
1928    
1929                    List<Layout> list = q.list();
1930    
1931                    if (list.size() == 2) {
1932                            return list.get(1);
1933                    }
1934                    else {
1935                            return null;
1936                    }
1937            }
1938    
1939            /**
1940             * Returns all the layouts that the user has permission to view where groupId = &#63;.
1941             *
1942             * @param groupId the group ID
1943             * @return the matching layouts that the user has permission to view
1944             */
1945            @Override
1946            public List<Layout> filterFindByGroupId(long groupId) {
1947                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1948                            QueryUtil.ALL_POS, null);
1949            }
1950    
1951            /**
1952             * Returns a range of all the layouts that the user has permission to view where groupId = &#63;.
1953             *
1954             * <p>
1955             * 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 LayoutModelImpl}. 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.
1956             * </p>
1957             *
1958             * @param groupId the group ID
1959             * @param start the lower bound of the range of layouts
1960             * @param end the upper bound of the range of layouts (not inclusive)
1961             * @return the range of matching layouts that the user has permission to view
1962             */
1963            @Override
1964            public List<Layout> filterFindByGroupId(long groupId, int start, int end) {
1965                    return filterFindByGroupId(groupId, start, end, null);
1966            }
1967    
1968            /**
1969             * Returns an ordered range of all the layouts that the user has permissions to view where groupId = &#63;.
1970             *
1971             * <p>
1972             * 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 LayoutModelImpl}. 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.
1973             * </p>
1974             *
1975             * @param groupId the group ID
1976             * @param start the lower bound of the range of layouts
1977             * @param end the upper bound of the range of layouts (not inclusive)
1978             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1979             * @return the ordered range of matching layouts that the user has permission to view
1980             */
1981            @Override
1982            public List<Layout> filterFindByGroupId(long groupId, int start, int end,
1983                    OrderByComparator<Layout> orderByComparator) {
1984                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1985                            return findByGroupId(groupId, start, end, orderByComparator);
1986                    }
1987    
1988                    StringBundler query = null;
1989    
1990                    if (orderByComparator != null) {
1991                            query = new StringBundler(3 +
1992                                            (orderByComparator.getOrderByFields().length * 3));
1993                    }
1994                    else {
1995                            query = new StringBundler(3);
1996                    }
1997    
1998                    if (getDB().isSupportsInlineDistinct()) {
1999                            query.append(_FILTER_SQL_SELECT_LAYOUT_WHERE);
2000                    }
2001                    else {
2002                            query.append(_FILTER_SQL_SELECT_LAYOUT_NO_INLINE_DISTINCT_WHERE_1);
2003                    }
2004    
2005                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2006    
2007                    if (!getDB().isSupportsInlineDistinct()) {
2008                            query.append(_FILTER_SQL_SELECT_LAYOUT_NO_INLINE_DISTINCT_WHERE_2);
2009                    }
2010    
2011                    if (orderByComparator != null) {
2012                            if (getDB().isSupportsInlineDistinct()) {
2013                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2014                                            orderByComparator, true);
2015                            }
2016                            else {
2017                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2018                                            orderByComparator, true);
2019                            }
2020                    }
2021                    else {
2022                            if (getDB().isSupportsInlineDistinct()) {
2023                                    query.append(LayoutModelImpl.ORDER_BY_JPQL);
2024                            }
2025                            else {
2026                                    query.append(LayoutModelImpl.ORDER_BY_SQL);
2027                            }
2028                    }
2029    
2030                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2031                                    Layout.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN,
2032                                    groupId);
2033    
2034                    Session session = null;
2035    
2036                    try {
2037                            session = openSession();
2038    
2039                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
2040    
2041                            if (getDB().isSupportsInlineDistinct()) {
2042                                    q.addEntity(_FILTER_ENTITY_ALIAS, LayoutImpl.class);
2043                            }
2044                            else {
2045                                    q.addEntity(_FILTER_ENTITY_TABLE, LayoutImpl.class);
2046                            }
2047    
2048                            QueryPos qPos = QueryPos.getInstance(q);
2049    
2050                            qPos.add(groupId);
2051    
2052                            return (List<Layout>)QueryUtil.list(q, getDialect(), start, end);
2053                    }
2054                    catch (Exception e) {
2055                            throw processException(e);
2056                    }
2057                    finally {
2058                            closeSession(session);
2059                    }
2060            }
2061    
2062            /**
2063             * Returns the layouts before and after the current layout in the ordered set of layouts that the user has permission to view where groupId = &#63;.
2064             *
2065             * @param plid the primary key of the current layout
2066             * @param groupId the group ID
2067             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2068             * @return the previous, current, and next layout
2069             * @throws NoSuchLayoutException if a layout with the primary key could not be found
2070             */
2071            @Override
2072            public Layout[] filterFindByGroupId_PrevAndNext(long plid, long groupId,
2073                    OrderByComparator<Layout> orderByComparator)
2074                    throws NoSuchLayoutException {
2075                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2076                            return findByGroupId_PrevAndNext(plid, groupId, orderByComparator);
2077                    }
2078    
2079                    Layout layout = findByPrimaryKey(plid);
2080    
2081                    Session session = null;
2082    
2083                    try {
2084                            session = openSession();
2085    
2086                            Layout[] array = new LayoutImpl[3];
2087    
2088                            array[0] = filterGetByGroupId_PrevAndNext(session, layout, groupId,
2089                                            orderByComparator, true);
2090    
2091                            array[1] = layout;
2092    
2093                            array[2] = filterGetByGroupId_PrevAndNext(session, layout, groupId,
2094                                            orderByComparator, false);
2095    
2096                            return array;
2097                    }
2098                    catch (Exception e) {
2099                            throw processException(e);
2100                    }
2101                    finally {
2102                            closeSession(session);
2103                    }
2104            }
2105    
2106            protected Layout filterGetByGroupId_PrevAndNext(Session session,
2107                    Layout layout, long groupId,
2108                    OrderByComparator<Layout> orderByComparator, boolean previous) {
2109                    StringBundler query = null;
2110    
2111                    if (orderByComparator != null) {
2112                            query = new StringBundler(6 +
2113                                            (orderByComparator.getOrderByFields().length * 6));
2114                    }
2115                    else {
2116                            query = new StringBundler(3);
2117                    }
2118    
2119                    if (getDB().isSupportsInlineDistinct()) {
2120                            query.append(_FILTER_SQL_SELECT_LAYOUT_WHERE);
2121                    }
2122                    else {
2123                            query.append(_FILTER_SQL_SELECT_LAYOUT_NO_INLINE_DISTINCT_WHERE_1);
2124                    }
2125    
2126                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2127    
2128                    if (!getDB().isSupportsInlineDistinct()) {
2129                            query.append(_FILTER_SQL_SELECT_LAYOUT_NO_INLINE_DISTINCT_WHERE_2);
2130                    }
2131    
2132                    if (orderByComparator != null) {
2133                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2134    
2135                            if (orderByConditionFields.length > 0) {
2136                                    query.append(WHERE_AND);
2137                            }
2138    
2139                            for (int i = 0; i < orderByConditionFields.length; i++) {
2140                                    if (getDB().isSupportsInlineDistinct()) {
2141                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2142                                    }
2143                                    else {
2144                                            query.append(_ORDER_BY_ENTITY_TABLE);
2145                                    }
2146    
2147                                    query.append(orderByConditionFields[i]);
2148    
2149                                    if ((i + 1) < orderByConditionFields.length) {
2150                                            if (orderByComparator.isAscending() ^ previous) {
2151                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2152                                            }
2153                                            else {
2154                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2155                                            }
2156                                    }
2157                                    else {
2158                                            if (orderByComparator.isAscending() ^ previous) {
2159                                                    query.append(WHERE_GREATER_THAN);
2160                                            }
2161                                            else {
2162                                                    query.append(WHERE_LESSER_THAN);
2163                                            }
2164                                    }
2165                            }
2166    
2167                            query.append(ORDER_BY_CLAUSE);
2168    
2169                            String[] orderByFields = orderByComparator.getOrderByFields();
2170    
2171                            for (int i = 0; i < orderByFields.length; i++) {
2172                                    if (getDB().isSupportsInlineDistinct()) {
2173                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2174                                    }
2175                                    else {
2176                                            query.append(_ORDER_BY_ENTITY_TABLE);
2177                                    }
2178    
2179                                    query.append(orderByFields[i]);
2180    
2181                                    if ((i + 1) < orderByFields.length) {
2182                                            if (orderByComparator.isAscending() ^ previous) {
2183                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2184                                            }
2185                                            else {
2186                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2187                                            }
2188                                    }
2189                                    else {
2190                                            if (orderByComparator.isAscending() ^ previous) {
2191                                                    query.append(ORDER_BY_ASC);
2192                                            }
2193                                            else {
2194                                                    query.append(ORDER_BY_DESC);
2195                                            }
2196                                    }
2197                            }
2198                    }
2199                    else {
2200                            if (getDB().isSupportsInlineDistinct()) {
2201                                    query.append(LayoutModelImpl.ORDER_BY_JPQL);
2202                            }
2203                            else {
2204                                    query.append(LayoutModelImpl.ORDER_BY_SQL);
2205                            }
2206                    }
2207    
2208                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2209                                    Layout.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN,
2210                                    groupId);
2211    
2212                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
2213    
2214                    q.setFirstResult(0);
2215                    q.setMaxResults(2);
2216    
2217                    if (getDB().isSupportsInlineDistinct()) {
2218                            q.addEntity(_FILTER_ENTITY_ALIAS, LayoutImpl.class);
2219                    }
2220                    else {
2221                            q.addEntity(_FILTER_ENTITY_TABLE, LayoutImpl.class);
2222                    }
2223    
2224                    QueryPos qPos = QueryPos.getInstance(q);
2225    
2226                    qPos.add(groupId);
2227    
2228                    if (orderByComparator != null) {
2229                            Object[] values = orderByComparator.getOrderByConditionValues(layout);
2230    
2231                            for (Object value : values) {
2232                                    qPos.add(value);
2233                            }
2234                    }
2235    
2236                    List<Layout> list = q.list();
2237    
2238                    if (list.size() == 2) {
2239                            return list.get(1);
2240                    }
2241                    else {
2242                            return null;
2243                    }
2244            }
2245    
2246            /**
2247             * Removes all the layouts where groupId = &#63; from the database.
2248             *
2249             * @param groupId the group ID
2250             */
2251            @Override
2252            public void removeByGroupId(long groupId) {
2253                    for (Layout layout : findByGroupId(groupId, QueryUtil.ALL_POS,
2254                                    QueryUtil.ALL_POS, null)) {
2255                            remove(layout);
2256                    }
2257            }
2258    
2259            /**
2260             * Returns the number of layouts where groupId = &#63;.
2261             *
2262             * @param groupId the group ID
2263             * @return the number of matching layouts
2264             */
2265            @Override
2266            public int countByGroupId(long groupId) {
2267                    FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
2268    
2269                    Object[] finderArgs = new Object[] { groupId };
2270    
2271                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
2272    
2273                    if (count == null) {
2274                            StringBundler query = new StringBundler(2);
2275    
2276                            query.append(_SQL_COUNT_LAYOUT_WHERE);
2277    
2278                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2279    
2280                            String sql = query.toString();
2281    
2282                            Session session = null;
2283    
2284                            try {
2285                                    session = openSession();
2286    
2287                                    Query q = session.createQuery(sql);
2288    
2289                                    QueryPos qPos = QueryPos.getInstance(q);
2290    
2291                                    qPos.add(groupId);
2292    
2293                                    count = (Long)q.uniqueResult();
2294    
2295                                    finderCache.putResult(finderPath, finderArgs, count);
2296                            }
2297                            catch (Exception e) {
2298                                    finderCache.removeResult(finderPath, finderArgs);
2299    
2300                                    throw processException(e);
2301                            }
2302                            finally {
2303                                    closeSession(session);
2304                            }
2305                    }
2306    
2307                    return count.intValue();
2308            }
2309    
2310            /**
2311             * Returns the number of layouts that the user has permission to view where groupId = &#63;.
2312             *
2313             * @param groupId the group ID
2314             * @return the number of matching layouts that the user has permission to view
2315             */
2316            @Override
2317            public int filterCountByGroupId(long groupId) {
2318                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2319                            return countByGroupId(groupId);
2320                    }
2321    
2322                    StringBundler query = new StringBundler(2);
2323    
2324                    query.append(_FILTER_SQL_COUNT_LAYOUT_WHERE);
2325    
2326                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2327    
2328                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2329                                    Layout.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN,
2330                                    groupId);
2331    
2332                    Session session = null;
2333    
2334                    try {
2335                            session = openSession();
2336    
2337                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
2338    
2339                            q.addScalar(COUNT_COLUMN_NAME,
2340                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
2341    
2342                            QueryPos qPos = QueryPos.getInstance(q);
2343    
2344                            qPos.add(groupId);
2345    
2346                            Long count = (Long)q.uniqueResult();
2347    
2348                            return count.intValue();
2349                    }
2350                    catch (Exception e) {
2351                            throw processException(e);
2352                    }
2353                    finally {
2354                            closeSession(session);
2355                    }
2356            }
2357    
2358            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "layout.groupId = ?";
2359            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
2360                    new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
2361                            LayoutModelImpl.FINDER_CACHE_ENABLED, LayoutImpl.class,
2362                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
2363                            new String[] {
2364                                    Long.class.getName(),
2365                                    
2366                            Integer.class.getName(), Integer.class.getName(),
2367                                    OrderByComparator.class.getName()
2368                            });
2369            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
2370                    new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
2371                            LayoutModelImpl.FINDER_CACHE_ENABLED, LayoutImpl.class,
2372                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
2373                            new String[] { Long.class.getName() },
2374                            LayoutModelImpl.COMPANYID_COLUMN_BITMASK |
2375                            LayoutModelImpl.PARENTLAYOUTID_COLUMN_BITMASK |
2376                            LayoutModelImpl.PRIORITY_COLUMN_BITMASK);
2377            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
2378                            LayoutModelImpl.FINDER_CACHE_ENABLED, Long.class,
2379                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
2380                            new String[] { Long.class.getName() });
2381    
2382            /**
2383             * Returns all the layouts where companyId = &#63;.
2384             *
2385             * @param companyId the company ID
2386             * @return the matching layouts
2387             */
2388            @Override
2389            public List<Layout> findByCompanyId(long companyId) {
2390                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2391                            null);
2392            }
2393    
2394            /**
2395             * Returns a range of all the layouts where companyId = &#63;.
2396             *
2397             * <p>
2398             * 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 LayoutModelImpl}. 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.
2399             * </p>
2400             *
2401             * @param companyId the company ID
2402             * @param start the lower bound of the range of layouts
2403             * @param end the upper bound of the range of layouts (not inclusive)
2404             * @return the range of matching layouts
2405             */
2406            @Override
2407            public List<Layout> findByCompanyId(long companyId, int start, int end) {
2408                    return findByCompanyId(companyId, start, end, null);
2409            }
2410    
2411            /**
2412             * Returns an ordered range of all the layouts where companyId = &#63;.
2413             *
2414             * <p>
2415             * 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 LayoutModelImpl}. 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.
2416             * </p>
2417             *
2418             * @param companyId the company ID
2419             * @param start the lower bound of the range of layouts
2420             * @param end the upper bound of the range of layouts (not inclusive)
2421             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2422             * @return the ordered range of matching layouts
2423             */
2424            @Override
2425            public List<Layout> findByCompanyId(long companyId, int start, int end,
2426                    OrderByComparator<Layout> orderByComparator) {
2427                    return findByCompanyId(companyId, start, end, orderByComparator, true);
2428            }
2429    
2430            /**
2431             * Returns an ordered range of all the layouts where companyId = &#63;.
2432             *
2433             * <p>
2434             * 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 LayoutModelImpl}. 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.
2435             * </p>
2436             *
2437             * @param companyId the company ID
2438             * @param start the lower bound of the range of layouts
2439             * @param end the upper bound of the range of layouts (not inclusive)
2440             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2441             * @param retrieveFromCache whether to retrieve from the finder cache
2442             * @return the ordered range of matching layouts
2443             */
2444            @Override
2445            public List<Layout> findByCompanyId(long companyId, int start, int end,
2446                    OrderByComparator<Layout> orderByComparator, boolean retrieveFromCache) {
2447                    boolean pagination = true;
2448                    FinderPath finderPath = null;
2449                    Object[] finderArgs = null;
2450    
2451                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2452                                    (orderByComparator == null)) {
2453                            pagination = false;
2454                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
2455                            finderArgs = new Object[] { companyId };
2456                    }
2457                    else {
2458                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
2459                            finderArgs = new Object[] { companyId, start, end, orderByComparator };
2460                    }
2461    
2462                    List<Layout> list = null;
2463    
2464                    if (retrieveFromCache) {
2465                            list = (List<Layout>)finderCache.getResult(finderPath, finderArgs,
2466                                            this);
2467    
2468                            if ((list != null) && !list.isEmpty()) {
2469                                    for (Layout layout : list) {
2470                                            if ((companyId != layout.getCompanyId())) {
2471                                                    list = null;
2472    
2473                                                    break;
2474                                            }
2475                                    }
2476                            }
2477                    }
2478    
2479                    if (list == null) {
2480                            StringBundler query = null;
2481    
2482                            if (orderByComparator != null) {
2483                                    query = new StringBundler(3 +
2484                                                    (orderByComparator.getOrderByFields().length * 3));
2485                            }
2486                            else {
2487                                    query = new StringBundler(3);
2488                            }
2489    
2490                            query.append(_SQL_SELECT_LAYOUT_WHERE);
2491    
2492                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2493    
2494                            if (orderByComparator != null) {
2495                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2496                                            orderByComparator);
2497                            }
2498                            else
2499                             if (pagination) {
2500                                    query.append(LayoutModelImpl.ORDER_BY_JPQL);
2501                            }
2502    
2503                            String sql = query.toString();
2504    
2505                            Session session = null;
2506    
2507                            try {
2508                                    session = openSession();
2509    
2510                                    Query q = session.createQuery(sql);
2511    
2512                                    QueryPos qPos = QueryPos.getInstance(q);
2513    
2514                                    qPos.add(companyId);
2515    
2516                                    if (!pagination) {
2517                                            list = (List<Layout>)QueryUtil.list(q, getDialect(), start,
2518                                                            end, false);
2519    
2520                                            Collections.sort(list);
2521    
2522                                            list = Collections.unmodifiableList(list);
2523                                    }
2524                                    else {
2525                                            list = (List<Layout>)QueryUtil.list(q, getDialect(), start,
2526                                                            end);
2527                                    }
2528    
2529                                    cacheResult(list);
2530    
2531                                    finderCache.putResult(finderPath, finderArgs, list);
2532                            }
2533                            catch (Exception e) {
2534                                    finderCache.removeResult(finderPath, finderArgs);
2535    
2536                                    throw processException(e);
2537                            }
2538                            finally {
2539                                    closeSession(session);
2540                            }
2541                    }
2542    
2543                    return list;
2544            }
2545    
2546            /**
2547             * Returns the first layout in the ordered set where companyId = &#63;.
2548             *
2549             * @param companyId the company ID
2550             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2551             * @return the first matching layout
2552             * @throws NoSuchLayoutException if a matching layout could not be found
2553             */
2554            @Override
2555            public Layout findByCompanyId_First(long companyId,
2556                    OrderByComparator<Layout> orderByComparator)
2557                    throws NoSuchLayoutException {
2558                    Layout layout = fetchByCompanyId_First(companyId, orderByComparator);
2559    
2560                    if (layout != null) {
2561                            return layout;
2562                    }
2563    
2564                    StringBundler msg = new StringBundler(4);
2565    
2566                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2567    
2568                    msg.append("companyId=");
2569                    msg.append(companyId);
2570    
2571                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2572    
2573                    throw new NoSuchLayoutException(msg.toString());
2574            }
2575    
2576            /**
2577             * Returns the first layout in the ordered set where companyId = &#63;.
2578             *
2579             * @param companyId the company ID
2580             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2581             * @return the first matching layout, or <code>null</code> if a matching layout could not be found
2582             */
2583            @Override
2584            public Layout fetchByCompanyId_First(long companyId,
2585                    OrderByComparator<Layout> orderByComparator) {
2586                    List<Layout> list = findByCompanyId(companyId, 0, 1, orderByComparator);
2587    
2588                    if (!list.isEmpty()) {
2589                            return list.get(0);
2590                    }
2591    
2592                    return null;
2593            }
2594    
2595            /**
2596             * Returns the last layout in the ordered set where companyId = &#63;.
2597             *
2598             * @param companyId the company ID
2599             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2600             * @return the last matching layout
2601             * @throws NoSuchLayoutException if a matching layout could not be found
2602             */
2603            @Override
2604            public Layout findByCompanyId_Last(long companyId,
2605                    OrderByComparator<Layout> orderByComparator)
2606                    throws NoSuchLayoutException {
2607                    Layout layout = fetchByCompanyId_Last(companyId, orderByComparator);
2608    
2609                    if (layout != null) {
2610                            return layout;
2611                    }
2612    
2613                    StringBundler msg = new StringBundler(4);
2614    
2615                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2616    
2617                    msg.append("companyId=");
2618                    msg.append(companyId);
2619    
2620                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2621    
2622                    throw new NoSuchLayoutException(msg.toString());
2623            }
2624    
2625            /**
2626             * Returns the last layout in the ordered set where companyId = &#63;.
2627             *
2628             * @param companyId the company ID
2629             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2630             * @return the last matching layout, or <code>null</code> if a matching layout could not be found
2631             */
2632            @Override
2633            public Layout fetchByCompanyId_Last(long companyId,
2634                    OrderByComparator<Layout> orderByComparator) {
2635                    int count = countByCompanyId(companyId);
2636    
2637                    if (count == 0) {
2638                            return null;
2639                    }
2640    
2641                    List<Layout> list = findByCompanyId(companyId, count - 1, count,
2642                                    orderByComparator);
2643    
2644                    if (!list.isEmpty()) {
2645                            return list.get(0);
2646                    }
2647    
2648                    return null;
2649            }
2650    
2651            /**
2652             * Returns the layouts before and after the current layout in the ordered set where companyId = &#63;.
2653             *
2654             * @param plid the primary key of the current layout
2655             * @param companyId the company ID
2656             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2657             * @return the previous, current, and next layout
2658             * @throws NoSuchLayoutException if a layout with the primary key could not be found
2659             */
2660            @Override
2661            public Layout[] findByCompanyId_PrevAndNext(long plid, long companyId,
2662                    OrderByComparator<Layout> orderByComparator)
2663                    throws NoSuchLayoutException {
2664                    Layout layout = findByPrimaryKey(plid);
2665    
2666                    Session session = null;
2667    
2668                    try {
2669                            session = openSession();
2670    
2671                            Layout[] array = new LayoutImpl[3];
2672    
2673                            array[0] = getByCompanyId_PrevAndNext(session, layout, companyId,
2674                                            orderByComparator, true);
2675    
2676                            array[1] = layout;
2677    
2678                            array[2] = getByCompanyId_PrevAndNext(session, layout, companyId,
2679                                            orderByComparator, false);
2680    
2681                            return array;
2682                    }
2683                    catch (Exception e) {
2684                            throw processException(e);
2685                    }
2686                    finally {
2687                            closeSession(session);
2688                    }
2689            }
2690    
2691            protected Layout getByCompanyId_PrevAndNext(Session session, Layout layout,
2692                    long companyId, OrderByComparator<Layout> orderByComparator,
2693                    boolean previous) {
2694                    StringBundler query = null;
2695    
2696                    if (orderByComparator != null) {
2697                            query = new StringBundler(6 +
2698                                            (orderByComparator.getOrderByFields().length * 6));
2699                    }
2700                    else {
2701                            query = new StringBundler(3);
2702                    }
2703    
2704                    query.append(_SQL_SELECT_LAYOUT_WHERE);
2705    
2706                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2707    
2708                    if (orderByComparator != null) {
2709                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2710    
2711                            if (orderByConditionFields.length > 0) {
2712                                    query.append(WHERE_AND);
2713                            }
2714    
2715                            for (int i = 0; i < orderByConditionFields.length; i++) {
2716                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2717                                    query.append(orderByConditionFields[i]);
2718    
2719                                    if ((i + 1) < orderByConditionFields.length) {
2720                                            if (orderByComparator.isAscending() ^ previous) {
2721                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2722                                            }
2723                                            else {
2724                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2725                                            }
2726                                    }
2727                                    else {
2728                                            if (orderByComparator.isAscending() ^ previous) {
2729                                                    query.append(WHERE_GREATER_THAN);
2730                                            }
2731                                            else {
2732                                                    query.append(WHERE_LESSER_THAN);
2733                                            }
2734                                    }
2735                            }
2736    
2737                            query.append(ORDER_BY_CLAUSE);
2738    
2739                            String[] orderByFields = orderByComparator.getOrderByFields();
2740    
2741                            for (int i = 0; i < orderByFields.length; i++) {
2742                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2743                                    query.append(orderByFields[i]);
2744    
2745                                    if ((i + 1) < orderByFields.length) {
2746                                            if (orderByComparator.isAscending() ^ previous) {
2747                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2748                                            }
2749                                            else {
2750                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2751                                            }
2752                                    }
2753                                    else {
2754                                            if (orderByComparator.isAscending() ^ previous) {
2755                                                    query.append(ORDER_BY_ASC);
2756                                            }
2757                                            else {
2758                                                    query.append(ORDER_BY_DESC);
2759                                            }
2760                                    }
2761                            }
2762                    }
2763                    else {
2764                            query.append(LayoutModelImpl.ORDER_BY_JPQL);
2765                    }
2766    
2767                    String sql = query.toString();
2768    
2769                    Query q = session.createQuery(sql);
2770    
2771                    q.setFirstResult(0);
2772                    q.setMaxResults(2);
2773    
2774                    QueryPos qPos = QueryPos.getInstance(q);
2775    
2776                    qPos.add(companyId);
2777    
2778                    if (orderByComparator != null) {
2779                            Object[] values = orderByComparator.getOrderByConditionValues(layout);
2780    
2781                            for (Object value : values) {
2782                                    qPos.add(value);
2783                            }
2784                    }
2785    
2786                    List<Layout> list = q.list();
2787    
2788                    if (list.size() == 2) {
2789                            return list.get(1);
2790                    }
2791                    else {
2792                            return null;
2793                    }
2794            }
2795    
2796            /**
2797             * Removes all the layouts where companyId = &#63; from the database.
2798             *
2799             * @param companyId the company ID
2800             */
2801            @Override
2802            public void removeByCompanyId(long companyId) {
2803                    for (Layout layout : findByCompanyId(companyId, QueryUtil.ALL_POS,
2804                                    QueryUtil.ALL_POS, null)) {
2805                            remove(layout);
2806                    }
2807            }
2808    
2809            /**
2810             * Returns the number of layouts where companyId = &#63;.
2811             *
2812             * @param companyId the company ID
2813             * @return the number of matching layouts
2814             */
2815            @Override
2816            public int countByCompanyId(long companyId) {
2817                    FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
2818    
2819                    Object[] finderArgs = new Object[] { companyId };
2820    
2821                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
2822    
2823                    if (count == null) {
2824                            StringBundler query = new StringBundler(2);
2825    
2826                            query.append(_SQL_COUNT_LAYOUT_WHERE);
2827    
2828                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2829    
2830                            String sql = query.toString();
2831    
2832                            Session session = null;
2833    
2834                            try {
2835                                    session = openSession();
2836    
2837                                    Query q = session.createQuery(sql);
2838    
2839                                    QueryPos qPos = QueryPos.getInstance(q);
2840    
2841                                    qPos.add(companyId);
2842    
2843                                    count = (Long)q.uniqueResult();
2844    
2845                                    finderCache.putResult(finderPath, finderArgs, count);
2846                            }
2847                            catch (Exception e) {
2848                                    finderCache.removeResult(finderPath, finderArgs);
2849    
2850                                    throw processException(e);
2851                            }
2852                            finally {
2853                                    closeSession(session);
2854                            }
2855                    }
2856    
2857                    return count.intValue();
2858            }
2859    
2860            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "layout.companyId = ?";
2861            public static final FinderPath FINDER_PATH_FETCH_BY_ICONIMAGEID = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
2862                            LayoutModelImpl.FINDER_CACHE_ENABLED, LayoutImpl.class,
2863                            FINDER_CLASS_NAME_ENTITY, "fetchByIconImageId",
2864                            new String[] { Long.class.getName() },
2865                            LayoutModelImpl.ICONIMAGEID_COLUMN_BITMASK);
2866            public static final FinderPath FINDER_PATH_COUNT_BY_ICONIMAGEID = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
2867                            LayoutModelImpl.FINDER_CACHE_ENABLED, Long.class,
2868                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByIconImageId",
2869                            new String[] { Long.class.getName() });
2870    
2871            /**
2872             * Returns the layout where iconImageId = &#63; or throws a {@link NoSuchLayoutException} if it could not be found.
2873             *
2874             * @param iconImageId the icon image ID
2875             * @return the matching layout
2876             * @throws NoSuchLayoutException if a matching layout could not be found
2877             */
2878            @Override
2879            public Layout findByIconImageId(long iconImageId)
2880                    throws NoSuchLayoutException {
2881                    Layout layout = fetchByIconImageId(iconImageId);
2882    
2883                    if (layout == null) {
2884                            StringBundler msg = new StringBundler(4);
2885    
2886                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2887    
2888                            msg.append("iconImageId=");
2889                            msg.append(iconImageId);
2890    
2891                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2892    
2893                            if (_log.isWarnEnabled()) {
2894                                    _log.warn(msg.toString());
2895                            }
2896    
2897                            throw new NoSuchLayoutException(msg.toString());
2898                    }
2899    
2900                    return layout;
2901            }
2902    
2903            /**
2904             * Returns the layout where iconImageId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
2905             *
2906             * @param iconImageId the icon image ID
2907             * @return the matching layout, or <code>null</code> if a matching layout could not be found
2908             */
2909            @Override
2910            public Layout fetchByIconImageId(long iconImageId) {
2911                    return fetchByIconImageId(iconImageId, true);
2912            }
2913    
2914            /**
2915             * Returns the layout where iconImageId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
2916             *
2917             * @param iconImageId the icon image ID
2918             * @param retrieveFromCache whether to retrieve from the finder cache
2919             * @return the matching layout, or <code>null</code> if a matching layout could not be found
2920             */
2921            @Override
2922            public Layout fetchByIconImageId(long iconImageId, boolean retrieveFromCache) {
2923                    Object[] finderArgs = new Object[] { iconImageId };
2924    
2925                    Object result = null;
2926    
2927                    if (retrieveFromCache) {
2928                            result = finderCache.getResult(FINDER_PATH_FETCH_BY_ICONIMAGEID,
2929                                            finderArgs, this);
2930                    }
2931    
2932                    if (result instanceof Layout) {
2933                            Layout layout = (Layout)result;
2934    
2935                            if ((iconImageId != layout.getIconImageId())) {
2936                                    result = null;
2937                            }
2938                    }
2939    
2940                    if (result == null) {
2941                            StringBundler query = new StringBundler(3);
2942    
2943                            query.append(_SQL_SELECT_LAYOUT_WHERE);
2944    
2945                            query.append(_FINDER_COLUMN_ICONIMAGEID_ICONIMAGEID_2);
2946    
2947                            String sql = query.toString();
2948    
2949                            Session session = null;
2950    
2951                            try {
2952                                    session = openSession();
2953    
2954                                    Query q = session.createQuery(sql);
2955    
2956                                    QueryPos qPos = QueryPos.getInstance(q);
2957    
2958                                    qPos.add(iconImageId);
2959    
2960                                    List<Layout> list = q.list();
2961    
2962                                    if (list.isEmpty()) {
2963                                            finderCache.putResult(FINDER_PATH_FETCH_BY_ICONIMAGEID,
2964                                                    finderArgs, list);
2965                                    }
2966                                    else {
2967                                            if ((list.size() > 1) && _log.isWarnEnabled()) {
2968                                                    _log.warn(
2969                                                            "LayoutPersistenceImpl.fetchByIconImageId(long, boolean) with parameters (" +
2970                                                            StringUtil.merge(finderArgs) +
2971                                                            ") 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.");
2972                                            }
2973    
2974                                            Layout layout = list.get(0);
2975    
2976                                            result = layout;
2977    
2978                                            cacheResult(layout);
2979    
2980                                            if ((layout.getIconImageId() != iconImageId)) {
2981                                                    finderCache.putResult(FINDER_PATH_FETCH_BY_ICONIMAGEID,
2982                                                            finderArgs, layout);
2983                                            }
2984                                    }
2985                            }
2986                            catch (Exception e) {
2987                                    finderCache.removeResult(FINDER_PATH_FETCH_BY_ICONIMAGEID,
2988                                            finderArgs);
2989    
2990                                    throw processException(e);
2991                            }
2992                            finally {
2993                                    closeSession(session);
2994                            }
2995                    }
2996    
2997                    if (result instanceof List<?>) {
2998                            return null;
2999                    }
3000                    else {
3001                            return (Layout)result;
3002                    }
3003            }
3004    
3005            /**
3006             * Removes the layout where iconImageId = &#63; from the database.
3007             *
3008             * @param iconImageId the icon image ID
3009             * @return the layout that was removed
3010             */
3011            @Override
3012            public Layout removeByIconImageId(long iconImageId)
3013                    throws NoSuchLayoutException {
3014                    Layout layout = findByIconImageId(iconImageId);
3015    
3016                    return remove(layout);
3017            }
3018    
3019            /**
3020             * Returns the number of layouts where iconImageId = &#63;.
3021             *
3022             * @param iconImageId the icon image ID
3023             * @return the number of matching layouts
3024             */
3025            @Override
3026            public int countByIconImageId(long iconImageId) {
3027                    FinderPath finderPath = FINDER_PATH_COUNT_BY_ICONIMAGEID;
3028    
3029                    Object[] finderArgs = new Object[] { iconImageId };
3030    
3031                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
3032    
3033                    if (count == null) {
3034                            StringBundler query = new StringBundler(2);
3035    
3036                            query.append(_SQL_COUNT_LAYOUT_WHERE);
3037    
3038                            query.append(_FINDER_COLUMN_ICONIMAGEID_ICONIMAGEID_2);
3039    
3040                            String sql = query.toString();
3041    
3042                            Session session = null;
3043    
3044                            try {
3045                                    session = openSession();
3046    
3047                                    Query q = session.createQuery(sql);
3048    
3049                                    QueryPos qPos = QueryPos.getInstance(q);
3050    
3051                                    qPos.add(iconImageId);
3052    
3053                                    count = (Long)q.uniqueResult();
3054    
3055                                    finderCache.putResult(finderPath, finderArgs, count);
3056                            }
3057                            catch (Exception e) {
3058                                    finderCache.removeResult(finderPath, finderArgs);
3059    
3060                                    throw processException(e);
3061                            }
3062                            finally {
3063                                    closeSession(session);
3064                            }
3065                    }
3066    
3067                    return count.intValue();
3068            }
3069    
3070            private static final String _FINDER_COLUMN_ICONIMAGEID_ICONIMAGEID_2 = "layout.iconImageId = ?";
3071            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_LAYOUTPROTOTYPEUUID =
3072                    new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
3073                            LayoutModelImpl.FINDER_CACHE_ENABLED, LayoutImpl.class,
3074                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
3075                            "findByLayoutPrototypeUuid",
3076                            new String[] {
3077                                    String.class.getName(),
3078                                    
3079                            Integer.class.getName(), Integer.class.getName(),
3080                                    OrderByComparator.class.getName()
3081                            });
3082            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LAYOUTPROTOTYPEUUID =
3083                    new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
3084                            LayoutModelImpl.FINDER_CACHE_ENABLED, LayoutImpl.class,
3085                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
3086                            "findByLayoutPrototypeUuid",
3087                            new String[] { String.class.getName() },
3088                            LayoutModelImpl.LAYOUTPROTOTYPEUUID_COLUMN_BITMASK |
3089                            LayoutModelImpl.PARENTLAYOUTID_COLUMN_BITMASK |
3090                            LayoutModelImpl.PRIORITY_COLUMN_BITMASK);
3091            public static final FinderPath FINDER_PATH_COUNT_BY_LAYOUTPROTOTYPEUUID = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
3092                            LayoutModelImpl.FINDER_CACHE_ENABLED, Long.class,
3093                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
3094                            "countByLayoutPrototypeUuid",
3095                            new String[] { String.class.getName() });
3096    
3097            /**
3098             * Returns all the layouts where layoutPrototypeUuid = &#63;.
3099             *
3100             * @param layoutPrototypeUuid the layout prototype uuid
3101             * @return the matching layouts
3102             */
3103            @Override
3104            public List<Layout> findByLayoutPrototypeUuid(String layoutPrototypeUuid) {
3105                    return findByLayoutPrototypeUuid(layoutPrototypeUuid,
3106                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3107            }
3108    
3109            /**
3110             * Returns a range of all the layouts where layoutPrototypeUuid = &#63;.
3111             *
3112             * <p>
3113             * 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 LayoutModelImpl}. 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.
3114             * </p>
3115             *
3116             * @param layoutPrototypeUuid the layout prototype uuid
3117             * @param start the lower bound of the range of layouts
3118             * @param end the upper bound of the range of layouts (not inclusive)
3119             * @return the range of matching layouts
3120             */
3121            @Override
3122            public List<Layout> findByLayoutPrototypeUuid(String layoutPrototypeUuid,
3123                    int start, int end) {
3124                    return findByLayoutPrototypeUuid(layoutPrototypeUuid, start, end, null);
3125            }
3126    
3127            /**
3128             * Returns an ordered range of all the layouts where layoutPrototypeUuid = &#63;.
3129             *
3130             * <p>
3131             * 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 LayoutModelImpl}. 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.
3132             * </p>
3133             *
3134             * @param layoutPrototypeUuid the layout prototype uuid
3135             * @param start the lower bound of the range of layouts
3136             * @param end the upper bound of the range of layouts (not inclusive)
3137             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3138             * @return the ordered range of matching layouts
3139             */
3140            @Override
3141            public List<Layout> findByLayoutPrototypeUuid(String layoutPrototypeUuid,
3142                    int start, int end, OrderByComparator<Layout> orderByComparator) {
3143                    return findByLayoutPrototypeUuid(layoutPrototypeUuid, start, end,
3144                            orderByComparator, true);
3145            }
3146    
3147            /**
3148             * Returns an ordered range of all the layouts where layoutPrototypeUuid = &#63;.
3149             *
3150             * <p>
3151             * 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 LayoutModelImpl}. 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.
3152             * </p>
3153             *
3154             * @param layoutPrototypeUuid the layout prototype uuid
3155             * @param start the lower bound of the range of layouts
3156             * @param end the upper bound of the range of layouts (not inclusive)
3157             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3158             * @param retrieveFromCache whether to retrieve from the finder cache
3159             * @return the ordered range of matching layouts
3160             */
3161            @Override
3162            public List<Layout> findByLayoutPrototypeUuid(String layoutPrototypeUuid,
3163                    int start, int end, OrderByComparator<Layout> orderByComparator,
3164                    boolean retrieveFromCache) {
3165                    boolean pagination = true;
3166                    FinderPath finderPath = null;
3167                    Object[] finderArgs = null;
3168    
3169                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3170                                    (orderByComparator == null)) {
3171                            pagination = false;
3172                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LAYOUTPROTOTYPEUUID;
3173                            finderArgs = new Object[] { layoutPrototypeUuid };
3174                    }
3175                    else {
3176                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_LAYOUTPROTOTYPEUUID;
3177                            finderArgs = new Object[] {
3178                                            layoutPrototypeUuid,
3179                                            
3180                                            start, end, orderByComparator
3181                                    };
3182                    }
3183    
3184                    List<Layout> list = null;
3185    
3186                    if (retrieveFromCache) {
3187                            list = (List<Layout>)finderCache.getResult(finderPath, finderArgs,
3188                                            this);
3189    
3190                            if ((list != null) && !list.isEmpty()) {
3191                                    for (Layout layout : list) {
3192                                            if (!Validator.equals(layoutPrototypeUuid,
3193                                                                    layout.getLayoutPrototypeUuid())) {
3194                                                    list = null;
3195    
3196                                                    break;
3197                                            }
3198                                    }
3199                            }
3200                    }
3201    
3202                    if (list == null) {
3203                            StringBundler query = null;
3204    
3205                            if (orderByComparator != null) {
3206                                    query = new StringBundler(3 +
3207                                                    (orderByComparator.getOrderByFields().length * 3));
3208                            }
3209                            else {
3210                                    query = new StringBundler(3);
3211                            }
3212    
3213                            query.append(_SQL_SELECT_LAYOUT_WHERE);
3214    
3215                            boolean bindLayoutPrototypeUuid = false;
3216    
3217                            if (layoutPrototypeUuid == null) {
3218                                    query.append(_FINDER_COLUMN_LAYOUTPROTOTYPEUUID_LAYOUTPROTOTYPEUUID_1);
3219                            }
3220                            else if (layoutPrototypeUuid.equals(StringPool.BLANK)) {
3221                                    query.append(_FINDER_COLUMN_LAYOUTPROTOTYPEUUID_LAYOUTPROTOTYPEUUID_3);
3222                            }
3223                            else {
3224                                    bindLayoutPrototypeUuid = true;
3225    
3226                                    query.append(_FINDER_COLUMN_LAYOUTPROTOTYPEUUID_LAYOUTPROTOTYPEUUID_2);
3227                            }
3228    
3229                            if (orderByComparator != null) {
3230                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3231                                            orderByComparator);
3232                            }
3233                            else
3234                             if (pagination) {
3235                                    query.append(LayoutModelImpl.ORDER_BY_JPQL);
3236                            }
3237    
3238                            String sql = query.toString();
3239    
3240                            Session session = null;
3241    
3242                            try {
3243                                    session = openSession();
3244    
3245                                    Query q = session.createQuery(sql);
3246    
3247                                    QueryPos qPos = QueryPos.getInstance(q);
3248    
3249                                    if (bindLayoutPrototypeUuid) {
3250                                            qPos.add(layoutPrototypeUuid);
3251                                    }
3252    
3253                                    if (!pagination) {
3254                                            list = (List<Layout>)QueryUtil.list(q, getDialect(), start,
3255                                                            end, false);
3256    
3257                                            Collections.sort(list);
3258    
3259                                            list = Collections.unmodifiableList(list);
3260                                    }
3261                                    else {
3262                                            list = (List<Layout>)QueryUtil.list(q, getDialect(), start,
3263                                                            end);
3264                                    }
3265    
3266                                    cacheResult(list);
3267    
3268                                    finderCache.putResult(finderPath, finderArgs, list);
3269                            }
3270                            catch (Exception e) {
3271                                    finderCache.removeResult(finderPath, finderArgs);
3272    
3273                                    throw processException(e);
3274                            }
3275                            finally {
3276                                    closeSession(session);
3277                            }
3278                    }
3279    
3280                    return list;
3281            }
3282    
3283            /**
3284             * Returns the first layout in the ordered set where layoutPrototypeUuid = &#63;.
3285             *
3286             * @param layoutPrototypeUuid the layout prototype uuid
3287             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3288             * @return the first matching layout
3289             * @throws NoSuchLayoutException if a matching layout could not be found
3290             */
3291            @Override
3292            public Layout findByLayoutPrototypeUuid_First(String layoutPrototypeUuid,
3293                    OrderByComparator<Layout> orderByComparator)
3294                    throws NoSuchLayoutException {
3295                    Layout layout = fetchByLayoutPrototypeUuid_First(layoutPrototypeUuid,
3296                                    orderByComparator);
3297    
3298                    if (layout != null) {
3299                            return layout;
3300                    }
3301    
3302                    StringBundler msg = new StringBundler(4);
3303    
3304                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3305    
3306                    msg.append("layoutPrototypeUuid=");
3307                    msg.append(layoutPrototypeUuid);
3308    
3309                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3310    
3311                    throw new NoSuchLayoutException(msg.toString());
3312            }
3313    
3314            /**
3315             * Returns the first layout in the ordered set where layoutPrototypeUuid = &#63;.
3316             *
3317             * @param layoutPrototypeUuid the layout prototype uuid
3318             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3319             * @return the first matching layout, or <code>null</code> if a matching layout could not be found
3320             */
3321            @Override
3322            public Layout fetchByLayoutPrototypeUuid_First(String layoutPrototypeUuid,
3323                    OrderByComparator<Layout> orderByComparator) {
3324                    List<Layout> list = findByLayoutPrototypeUuid(layoutPrototypeUuid, 0,
3325                                    1, orderByComparator);
3326    
3327                    if (!list.isEmpty()) {
3328                            return list.get(0);
3329                    }
3330    
3331                    return null;
3332            }
3333    
3334            /**
3335             * Returns the last layout in the ordered set where layoutPrototypeUuid = &#63;.
3336             *
3337             * @param layoutPrototypeUuid the layout prototype uuid
3338             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3339             * @return the last matching layout
3340             * @throws NoSuchLayoutException if a matching layout could not be found
3341             */
3342            @Override
3343            public Layout findByLayoutPrototypeUuid_Last(String layoutPrototypeUuid,
3344                    OrderByComparator<Layout> orderByComparator)
3345                    throws NoSuchLayoutException {
3346                    Layout layout = fetchByLayoutPrototypeUuid_Last(layoutPrototypeUuid,
3347                                    orderByComparator);
3348    
3349                    if (layout != null) {
3350                            return layout;
3351                    }
3352    
3353                    StringBundler msg = new StringBundler(4);
3354    
3355                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3356    
3357                    msg.append("layoutPrototypeUuid=");
3358                    msg.append(layoutPrototypeUuid);
3359    
3360                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3361    
3362                    throw new NoSuchLayoutException(msg.toString());
3363            }
3364    
3365            /**
3366             * Returns the last layout in the ordered set where layoutPrototypeUuid = &#63;.
3367             *
3368             * @param layoutPrototypeUuid the layout prototype uuid
3369             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3370             * @return the last matching layout, or <code>null</code> if a matching layout could not be found
3371             */
3372            @Override
3373            public Layout fetchByLayoutPrototypeUuid_Last(String layoutPrototypeUuid,
3374                    OrderByComparator<Layout> orderByComparator) {
3375                    int count = countByLayoutPrototypeUuid(layoutPrototypeUuid);
3376    
3377                    if (count == 0) {
3378                            return null;
3379                    }
3380    
3381                    List<Layout> list = findByLayoutPrototypeUuid(layoutPrototypeUuid,
3382                                    count - 1, count, orderByComparator);
3383    
3384                    if (!list.isEmpty()) {
3385                            return list.get(0);
3386                    }
3387    
3388                    return null;
3389            }
3390    
3391            /**
3392             * Returns the layouts before and after the current layout in the ordered set where layoutPrototypeUuid = &#63;.
3393             *
3394             * @param plid the primary key of the current layout
3395             * @param layoutPrototypeUuid the layout prototype uuid
3396             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3397             * @return the previous, current, and next layout
3398             * @throws NoSuchLayoutException if a layout with the primary key could not be found
3399             */
3400            @Override
3401            public Layout[] findByLayoutPrototypeUuid_PrevAndNext(long plid,
3402                    String layoutPrototypeUuid, OrderByComparator<Layout> orderByComparator)
3403                    throws NoSuchLayoutException {
3404                    Layout layout = findByPrimaryKey(plid);
3405    
3406                    Session session = null;
3407    
3408                    try {
3409                            session = openSession();
3410    
3411                            Layout[] array = new LayoutImpl[3];
3412    
3413                            array[0] = getByLayoutPrototypeUuid_PrevAndNext(session, layout,
3414                                            layoutPrototypeUuid, orderByComparator, true);
3415    
3416                            array[1] = layout;
3417    
3418                            array[2] = getByLayoutPrototypeUuid_PrevAndNext(session, layout,
3419                                            layoutPrototypeUuid, orderByComparator, false);
3420    
3421                            return array;
3422                    }
3423                    catch (Exception e) {
3424                            throw processException(e);
3425                    }
3426                    finally {
3427                            closeSession(session);
3428                    }
3429            }
3430    
3431            protected Layout getByLayoutPrototypeUuid_PrevAndNext(Session session,
3432                    Layout layout, String layoutPrototypeUuid,
3433                    OrderByComparator<Layout> orderByComparator, boolean previous) {
3434                    StringBundler query = null;
3435    
3436                    if (orderByComparator != null) {
3437                            query = new StringBundler(6 +
3438                                            (orderByComparator.getOrderByFields().length * 6));
3439                    }
3440                    else {
3441                            query = new StringBundler(3);
3442                    }
3443    
3444                    query.append(_SQL_SELECT_LAYOUT_WHERE);
3445    
3446                    boolean bindLayoutPrototypeUuid = false;
3447    
3448                    if (layoutPrototypeUuid == null) {
3449                            query.append(_FINDER_COLUMN_LAYOUTPROTOTYPEUUID_LAYOUTPROTOTYPEUUID_1);
3450                    }
3451                    else if (layoutPrototypeUuid.equals(StringPool.BLANK)) {
3452                            query.append(_FINDER_COLUMN_LAYOUTPROTOTYPEUUID_LAYOUTPROTOTYPEUUID_3);
3453                    }
3454                    else {
3455                            bindLayoutPrototypeUuid = true;
3456    
3457                            query.append(_FINDER_COLUMN_LAYOUTPROTOTYPEUUID_LAYOUTPROTOTYPEUUID_2);
3458                    }
3459    
3460                    if (orderByComparator != null) {
3461                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3462    
3463                            if (orderByConditionFields.length > 0) {
3464                                    query.append(WHERE_AND);
3465                            }
3466    
3467                            for (int i = 0; i < orderByConditionFields.length; i++) {
3468                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3469                                    query.append(orderByConditionFields[i]);
3470    
3471                                    if ((i + 1) < orderByConditionFields.length) {
3472                                            if (orderByComparator.isAscending() ^ previous) {
3473                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3474                                            }
3475                                            else {
3476                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3477                                            }
3478                                    }
3479                                    else {
3480                                            if (orderByComparator.isAscending() ^ previous) {
3481                                                    query.append(WHERE_GREATER_THAN);
3482                                            }
3483                                            else {
3484                                                    query.append(WHERE_LESSER_THAN);
3485                                            }
3486                                    }
3487                            }
3488    
3489                            query.append(ORDER_BY_CLAUSE);
3490    
3491                            String[] orderByFields = orderByComparator.getOrderByFields();
3492    
3493                            for (int i = 0; i < orderByFields.length; i++) {
3494                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3495                                    query.append(orderByFields[i]);
3496    
3497                                    if ((i + 1) < orderByFields.length) {
3498                                            if (orderByComparator.isAscending() ^ previous) {
3499                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3500                                            }
3501                                            else {
3502                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3503                                            }
3504                                    }
3505                                    else {
3506                                            if (orderByComparator.isAscending() ^ previous) {
3507                                                    query.append(ORDER_BY_ASC);
3508                                            }
3509                                            else {
3510                                                    query.append(ORDER_BY_DESC);
3511                                            }
3512                                    }
3513                            }
3514                    }
3515                    else {
3516                            query.append(LayoutModelImpl.ORDER_BY_JPQL);
3517                    }
3518    
3519                    String sql = query.toString();
3520    
3521                    Query q = session.createQuery(sql);
3522    
3523                    q.setFirstResult(0);
3524                    q.setMaxResults(2);
3525    
3526                    QueryPos qPos = QueryPos.getInstance(q);
3527    
3528                    if (bindLayoutPrototypeUuid) {
3529                            qPos.add(layoutPrototypeUuid);
3530                    }
3531    
3532                    if (orderByComparator != null) {
3533                            Object[] values = orderByComparator.getOrderByConditionValues(layout);
3534    
3535                            for (Object value : values) {
3536                                    qPos.add(value);
3537                            }
3538                    }
3539    
3540                    List<Layout> list = q.list();
3541    
3542                    if (list.size() == 2) {
3543                            return list.get(1);
3544                    }
3545                    else {
3546                            return null;
3547                    }
3548            }
3549    
3550            /**
3551             * Removes all the layouts where layoutPrototypeUuid = &#63; from the database.
3552             *
3553             * @param layoutPrototypeUuid the layout prototype uuid
3554             */
3555            @Override
3556            public void removeByLayoutPrototypeUuid(String layoutPrototypeUuid) {
3557                    for (Layout layout : findByLayoutPrototypeUuid(layoutPrototypeUuid,
3558                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3559                            remove(layout);
3560                    }
3561            }
3562    
3563            /**
3564             * Returns the number of layouts where layoutPrototypeUuid = &#63;.
3565             *
3566             * @param layoutPrototypeUuid the layout prototype uuid
3567             * @return the number of matching layouts
3568             */
3569            @Override
3570            public int countByLayoutPrototypeUuid(String layoutPrototypeUuid) {
3571                    FinderPath finderPath = FINDER_PATH_COUNT_BY_LAYOUTPROTOTYPEUUID;
3572    
3573                    Object[] finderArgs = new Object[] { layoutPrototypeUuid };
3574    
3575                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
3576    
3577                    if (count == null) {
3578                            StringBundler query = new StringBundler(2);
3579    
3580                            query.append(_SQL_COUNT_LAYOUT_WHERE);
3581    
3582                            boolean bindLayoutPrototypeUuid = false;
3583    
3584                            if (layoutPrototypeUuid == null) {
3585                                    query.append(_FINDER_COLUMN_LAYOUTPROTOTYPEUUID_LAYOUTPROTOTYPEUUID_1);
3586                            }
3587                            else if (layoutPrototypeUuid.equals(StringPool.BLANK)) {
3588                                    query.append(_FINDER_COLUMN_LAYOUTPROTOTYPEUUID_LAYOUTPROTOTYPEUUID_3);
3589                            }
3590                            else {
3591                                    bindLayoutPrototypeUuid = true;
3592    
3593                                    query.append(_FINDER_COLUMN_LAYOUTPROTOTYPEUUID_LAYOUTPROTOTYPEUUID_2);
3594                            }
3595    
3596                            String sql = query.toString();
3597    
3598                            Session session = null;
3599    
3600                            try {
3601                                    session = openSession();
3602    
3603                                    Query q = session.createQuery(sql);
3604    
3605                                    QueryPos qPos = QueryPos.getInstance(q);
3606    
3607                                    if (bindLayoutPrototypeUuid) {
3608                                            qPos.add(layoutPrototypeUuid);
3609                                    }
3610    
3611                                    count = (Long)q.uniqueResult();
3612    
3613                                    finderCache.putResult(finderPath, finderArgs, count);
3614                            }
3615                            catch (Exception e) {
3616                                    finderCache.removeResult(finderPath, finderArgs);
3617    
3618                                    throw processException(e);
3619                            }
3620                            finally {
3621                                    closeSession(session);
3622                            }
3623                    }
3624    
3625                    return count.intValue();
3626            }
3627    
3628            private static final String _FINDER_COLUMN_LAYOUTPROTOTYPEUUID_LAYOUTPROTOTYPEUUID_1 =
3629                    "layout.layoutPrototypeUuid IS NULL";
3630            private static final String _FINDER_COLUMN_LAYOUTPROTOTYPEUUID_LAYOUTPROTOTYPEUUID_2 =
3631                    "layout.layoutPrototypeUuid = ?";
3632            private static final String _FINDER_COLUMN_LAYOUTPROTOTYPEUUID_LAYOUTPROTOTYPEUUID_3 =
3633                    "(layout.layoutPrototypeUuid IS NULL OR layout.layoutPrototypeUuid = '')";
3634            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_SOURCEPROTOTYPELAYOUTUUID =
3635                    new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
3636                            LayoutModelImpl.FINDER_CACHE_ENABLED, LayoutImpl.class,
3637                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
3638                            "findBySourcePrototypeLayoutUuid",
3639                            new String[] {
3640                                    String.class.getName(),
3641                                    
3642                            Integer.class.getName(), Integer.class.getName(),
3643                                    OrderByComparator.class.getName()
3644                            });
3645            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SOURCEPROTOTYPELAYOUTUUID =
3646                    new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
3647                            LayoutModelImpl.FINDER_CACHE_ENABLED, LayoutImpl.class,
3648                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
3649                            "findBySourcePrototypeLayoutUuid",
3650                            new String[] { String.class.getName() },
3651                            LayoutModelImpl.SOURCEPROTOTYPELAYOUTUUID_COLUMN_BITMASK |
3652                            LayoutModelImpl.PARENTLAYOUTID_COLUMN_BITMASK |
3653                            LayoutModelImpl.PRIORITY_COLUMN_BITMASK);
3654            public static final FinderPath FINDER_PATH_COUNT_BY_SOURCEPROTOTYPELAYOUTUUID =
3655                    new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
3656                            LayoutModelImpl.FINDER_CACHE_ENABLED, Long.class,
3657                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
3658                            "countBySourcePrototypeLayoutUuid",
3659                            new String[] { String.class.getName() });
3660    
3661            /**
3662             * Returns all the layouts where sourcePrototypeLayoutUuid = &#63;.
3663             *
3664             * @param sourcePrototypeLayoutUuid the source prototype layout uuid
3665             * @return the matching layouts
3666             */
3667            @Override
3668            public List<Layout> findBySourcePrototypeLayoutUuid(
3669                    String sourcePrototypeLayoutUuid) {
3670                    return findBySourcePrototypeLayoutUuid(sourcePrototypeLayoutUuid,
3671                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3672            }
3673    
3674            /**
3675             * Returns a range of all the layouts where sourcePrototypeLayoutUuid = &#63;.
3676             *
3677             * <p>
3678             * 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 LayoutModelImpl}. 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.
3679             * </p>
3680             *
3681             * @param sourcePrototypeLayoutUuid the source prototype layout uuid
3682             * @param start the lower bound of the range of layouts
3683             * @param end the upper bound of the range of layouts (not inclusive)
3684             * @return the range of matching layouts
3685             */
3686            @Override
3687            public List<Layout> findBySourcePrototypeLayoutUuid(
3688                    String sourcePrototypeLayoutUuid, int start, int end) {
3689                    return findBySourcePrototypeLayoutUuid(sourcePrototypeLayoutUuid,
3690                            start, end, null);
3691            }
3692    
3693            /**
3694             * Returns an ordered range of all the layouts where sourcePrototypeLayoutUuid = &#63;.
3695             *
3696             * <p>
3697             * 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 LayoutModelImpl}. 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.
3698             * </p>
3699             *
3700             * @param sourcePrototypeLayoutUuid the source prototype layout uuid
3701             * @param start the lower bound of the range of layouts
3702             * @param end the upper bound of the range of layouts (not inclusive)
3703             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3704             * @return the ordered range of matching layouts
3705             */
3706            @Override
3707            public List<Layout> findBySourcePrototypeLayoutUuid(
3708                    String sourcePrototypeLayoutUuid, int start, int end,
3709                    OrderByComparator<Layout> orderByComparator) {
3710                    return findBySourcePrototypeLayoutUuid(sourcePrototypeLayoutUuid,
3711                            start, end, orderByComparator, true);
3712            }
3713    
3714            /**
3715             * Returns an ordered range of all the layouts where sourcePrototypeLayoutUuid = &#63;.
3716             *
3717             * <p>
3718             * 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 LayoutModelImpl}. 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.
3719             * </p>
3720             *
3721             * @param sourcePrototypeLayoutUuid the source prototype layout uuid
3722             * @param start the lower bound of the range of layouts
3723             * @param end the upper bound of the range of layouts (not inclusive)
3724             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3725             * @param retrieveFromCache whether to retrieve from the finder cache
3726             * @return the ordered range of matching layouts
3727             */
3728            @Override
3729            public List<Layout> findBySourcePrototypeLayoutUuid(
3730                    String sourcePrototypeLayoutUuid, int start, int end,
3731                    OrderByComparator<Layout> orderByComparator, boolean retrieveFromCache) {
3732                    boolean pagination = true;
3733                    FinderPath finderPath = null;
3734                    Object[] finderArgs = null;
3735    
3736                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3737                                    (orderByComparator == null)) {
3738                            pagination = false;
3739                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SOURCEPROTOTYPELAYOUTUUID;
3740                            finderArgs = new Object[] { sourcePrototypeLayoutUuid };
3741                    }
3742                    else {
3743                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_SOURCEPROTOTYPELAYOUTUUID;
3744                            finderArgs = new Object[] {
3745                                            sourcePrototypeLayoutUuid,
3746                                            
3747                                            start, end, orderByComparator
3748                                    };
3749                    }
3750    
3751                    List<Layout> list = null;
3752    
3753                    if (retrieveFromCache) {
3754                            list = (List<Layout>)finderCache.getResult(finderPath, finderArgs,
3755                                            this);
3756    
3757                            if ((list != null) && !list.isEmpty()) {
3758                                    for (Layout layout : list) {
3759                                            if (!Validator.equals(sourcePrototypeLayoutUuid,
3760                                                                    layout.getSourcePrototypeLayoutUuid())) {
3761                                                    list = null;
3762    
3763                                                    break;
3764                                            }
3765                                    }
3766                            }
3767                    }
3768    
3769                    if (list == null) {
3770                            StringBundler query = null;
3771    
3772                            if (orderByComparator != null) {
3773                                    query = new StringBundler(3 +
3774                                                    (orderByComparator.getOrderByFields().length * 3));
3775                            }
3776                            else {
3777                                    query = new StringBundler(3);
3778                            }
3779    
3780                            query.append(_SQL_SELECT_LAYOUT_WHERE);
3781    
3782                            boolean bindSourcePrototypeLayoutUuid = false;
3783    
3784                            if (sourcePrototypeLayoutUuid == null) {
3785                                    query.append(_FINDER_COLUMN_SOURCEPROTOTYPELAYOUTUUID_SOURCEPROTOTYPELAYOUTUUID_1);
3786                            }
3787                            else if (sourcePrototypeLayoutUuid.equals(StringPool.BLANK)) {
3788                                    query.append(_FINDER_COLUMN_SOURCEPROTOTYPELAYOUTUUID_SOURCEPROTOTYPELAYOUTUUID_3);
3789                            }
3790                            else {
3791                                    bindSourcePrototypeLayoutUuid = true;
3792    
3793                                    query.append(_FINDER_COLUMN_SOURCEPROTOTYPELAYOUTUUID_SOURCEPROTOTYPELAYOUTUUID_2);
3794                            }
3795    
3796                            if (orderByComparator != null) {
3797                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3798                                            orderByComparator);
3799                            }
3800                            else
3801                             if (pagination) {
3802                                    query.append(LayoutModelImpl.ORDER_BY_JPQL);
3803                            }
3804    
3805                            String sql = query.toString();
3806    
3807                            Session session = null;
3808    
3809                            try {
3810                                    session = openSession();
3811    
3812                                    Query q = session.createQuery(sql);
3813    
3814                                    QueryPos qPos = QueryPos.getInstance(q);
3815    
3816                                    if (bindSourcePrototypeLayoutUuid) {
3817                                            qPos.add(sourcePrototypeLayoutUuid);
3818                                    }
3819    
3820                                    if (!pagination) {
3821                                            list = (List<Layout>)QueryUtil.list(q, getDialect(), start,
3822                                                            end, false);
3823    
3824                                            Collections.sort(list);
3825    
3826                                            list = Collections.unmodifiableList(list);
3827                                    }
3828                                    else {
3829                                            list = (List<Layout>)QueryUtil.list(q, getDialect(), start,
3830                                                            end);
3831                                    }
3832    
3833                                    cacheResult(list);
3834    
3835                                    finderCache.putResult(finderPath, finderArgs, list);
3836                            }
3837                            catch (Exception e) {
3838                                    finderCache.removeResult(finderPath, finderArgs);
3839    
3840                                    throw processException(e);
3841                            }
3842                            finally {
3843                                    closeSession(session);
3844                            }
3845                    }
3846    
3847                    return list;
3848            }
3849    
3850            /**
3851             * Returns the first layout in the ordered set where sourcePrototypeLayoutUuid = &#63;.
3852             *
3853             * @param sourcePrototypeLayoutUuid the source prototype layout uuid
3854             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3855             * @return the first matching layout
3856             * @throws NoSuchLayoutException if a matching layout could not be found
3857             */
3858            @Override
3859            public Layout findBySourcePrototypeLayoutUuid_First(
3860                    String sourcePrototypeLayoutUuid,
3861                    OrderByComparator<Layout> orderByComparator)
3862                    throws NoSuchLayoutException {
3863                    Layout layout = fetchBySourcePrototypeLayoutUuid_First(sourcePrototypeLayoutUuid,
3864                                    orderByComparator);
3865    
3866                    if (layout != null) {
3867                            return layout;
3868                    }
3869    
3870                    StringBundler msg = new StringBundler(4);
3871    
3872                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3873    
3874                    msg.append("sourcePrototypeLayoutUuid=");
3875                    msg.append(sourcePrototypeLayoutUuid);
3876    
3877                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3878    
3879                    throw new NoSuchLayoutException(msg.toString());
3880            }
3881    
3882            /**
3883             * Returns the first layout in the ordered set where sourcePrototypeLayoutUuid = &#63;.
3884             *
3885             * @param sourcePrototypeLayoutUuid the source prototype layout uuid
3886             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3887             * @return the first matching layout, or <code>null</code> if a matching layout could not be found
3888             */
3889            @Override
3890            public Layout fetchBySourcePrototypeLayoutUuid_First(
3891                    String sourcePrototypeLayoutUuid,
3892                    OrderByComparator<Layout> orderByComparator) {
3893                    List<Layout> list = findBySourcePrototypeLayoutUuid(sourcePrototypeLayoutUuid,
3894                                    0, 1, orderByComparator);
3895    
3896                    if (!list.isEmpty()) {
3897                            return list.get(0);
3898                    }
3899    
3900                    return null;
3901            }
3902    
3903            /**
3904             * Returns the last layout in the ordered set where sourcePrototypeLayoutUuid = &#63;.
3905             *
3906             * @param sourcePrototypeLayoutUuid the source prototype layout uuid
3907             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3908             * @return the last matching layout
3909             * @throws NoSuchLayoutException if a matching layout could not be found
3910             */
3911            @Override
3912            public Layout findBySourcePrototypeLayoutUuid_Last(
3913                    String sourcePrototypeLayoutUuid,
3914                    OrderByComparator<Layout> orderByComparator)
3915                    throws NoSuchLayoutException {
3916                    Layout layout = fetchBySourcePrototypeLayoutUuid_Last(sourcePrototypeLayoutUuid,
3917                                    orderByComparator);
3918    
3919                    if (layout != null) {
3920                            return layout;
3921                    }
3922    
3923                    StringBundler msg = new StringBundler(4);
3924    
3925                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3926    
3927                    msg.append("sourcePrototypeLayoutUuid=");
3928                    msg.append(sourcePrototypeLayoutUuid);
3929    
3930                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3931    
3932                    throw new NoSuchLayoutException(msg.toString());
3933            }
3934    
3935            /**
3936             * Returns the last layout in the ordered set where sourcePrototypeLayoutUuid = &#63;.
3937             *
3938             * @param sourcePrototypeLayoutUuid the source prototype layout uuid
3939             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3940             * @return the last matching layout, or <code>null</code> if a matching layout could not be found
3941             */
3942            @Override
3943            public Layout fetchBySourcePrototypeLayoutUuid_Last(
3944                    String sourcePrototypeLayoutUuid,
3945                    OrderByComparator<Layout> orderByComparator) {
3946                    int count = countBySourcePrototypeLayoutUuid(sourcePrototypeLayoutUuid);
3947    
3948                    if (count == 0) {
3949                            return null;
3950                    }
3951    
3952                    List<Layout> list = findBySourcePrototypeLayoutUuid(sourcePrototypeLayoutUuid,
3953                                    count - 1, count, orderByComparator);
3954    
3955                    if (!list.isEmpty()) {
3956                            return list.get(0);
3957                    }
3958    
3959                    return null;
3960            }
3961    
3962            /**
3963             * Returns the layouts before and after the current layout in the ordered set where sourcePrototypeLayoutUuid = &#63;.
3964             *
3965             * @param plid the primary key of the current layout
3966             * @param sourcePrototypeLayoutUuid the source prototype layout uuid
3967             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3968             * @return the previous, current, and next layout
3969             * @throws NoSuchLayoutException if a layout with the primary key could not be found
3970             */
3971            @Override
3972            public Layout[] findBySourcePrototypeLayoutUuid_PrevAndNext(long plid,
3973                    String sourcePrototypeLayoutUuid,
3974                    OrderByComparator<Layout> orderByComparator)
3975                    throws NoSuchLayoutException {
3976                    Layout layout = findByPrimaryKey(plid);
3977    
3978                    Session session = null;
3979    
3980                    try {
3981                            session = openSession();
3982    
3983                            Layout[] array = new LayoutImpl[3];
3984    
3985                            array[0] = getBySourcePrototypeLayoutUuid_PrevAndNext(session,
3986                                            layout, sourcePrototypeLayoutUuid, orderByComparator, true);
3987    
3988                            array[1] = layout;
3989    
3990                            array[2] = getBySourcePrototypeLayoutUuid_PrevAndNext(session,
3991                                            layout, sourcePrototypeLayoutUuid, orderByComparator, false);
3992    
3993                            return array;
3994                    }
3995                    catch (Exception e) {
3996                            throw processException(e);
3997                    }
3998                    finally {
3999                            closeSession(session);
4000                    }
4001            }
4002    
4003            protected Layout getBySourcePrototypeLayoutUuid_PrevAndNext(
4004                    Session session, Layout layout, String sourcePrototypeLayoutUuid,
4005                    OrderByComparator<Layout> orderByComparator, boolean previous) {
4006                    StringBundler query = null;
4007    
4008                    if (orderByComparator != null) {
4009                            query = new StringBundler(6 +
4010                                            (orderByComparator.getOrderByFields().length * 6));
4011                    }
4012                    else {
4013                            query = new StringBundler(3);
4014                    }
4015    
4016                    query.append(_SQL_SELECT_LAYOUT_WHERE);
4017    
4018                    boolean bindSourcePrototypeLayoutUuid = false;
4019    
4020                    if (sourcePrototypeLayoutUuid == null) {
4021                            query.append(_FINDER_COLUMN_SOURCEPROTOTYPELAYOUTUUID_SOURCEPROTOTYPELAYOUTUUID_1);
4022                    }
4023                    else if (sourcePrototypeLayoutUuid.equals(StringPool.BLANK)) {
4024                            query.append(_FINDER_COLUMN_SOURCEPROTOTYPELAYOUTUUID_SOURCEPROTOTYPELAYOUTUUID_3);
4025                    }
4026                    else {
4027                            bindSourcePrototypeLayoutUuid = true;
4028    
4029                            query.append(_FINDER_COLUMN_SOURCEPROTOTYPELAYOUTUUID_SOURCEPROTOTYPELAYOUTUUID_2);
4030                    }
4031    
4032                    if (orderByComparator != null) {
4033                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4034    
4035                            if (orderByConditionFields.length > 0) {
4036                                    query.append(WHERE_AND);
4037                            }
4038    
4039                            for (int i = 0; i < orderByConditionFields.length; i++) {
4040                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4041                                    query.append(orderByConditionFields[i]);
4042    
4043                                    if ((i + 1) < orderByConditionFields.length) {
4044                                            if (orderByComparator.isAscending() ^ previous) {
4045                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4046                                            }
4047                                            else {
4048                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4049                                            }
4050                                    }
4051                                    else {
4052                                            if (orderByComparator.isAscending() ^ previous) {
4053                                                    query.append(WHERE_GREATER_THAN);
4054                                            }
4055                                            else {
4056                                                    query.append(WHERE_LESSER_THAN);
4057                                            }
4058                                    }
4059                            }
4060    
4061                            query.append(ORDER_BY_CLAUSE);
4062    
4063                            String[] orderByFields = orderByComparator.getOrderByFields();
4064    
4065                            for (int i = 0; i < orderByFields.length; i++) {
4066                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4067                                    query.append(orderByFields[i]);
4068    
4069                                    if ((i + 1) < orderByFields.length) {
4070                                            if (orderByComparator.isAscending() ^ previous) {
4071                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4072                                            }
4073                                            else {
4074                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4075                                            }
4076                                    }
4077                                    else {
4078                                            if (orderByComparator.isAscending() ^ previous) {
4079                                                    query.append(ORDER_BY_ASC);
4080                                            }
4081                                            else {
4082                                                    query.append(ORDER_BY_DESC);
4083                                            }
4084                                    }
4085                            }
4086                    }
4087                    else {
4088                            query.append(LayoutModelImpl.ORDER_BY_JPQL);
4089                    }
4090    
4091                    String sql = query.toString();
4092    
4093                    Query q = session.createQuery(sql);
4094    
4095                    q.setFirstResult(0);
4096                    q.setMaxResults(2);
4097    
4098                    QueryPos qPos = QueryPos.getInstance(q);
4099    
4100                    if (bindSourcePrototypeLayoutUuid) {
4101                            qPos.add(sourcePrototypeLayoutUuid);
4102                    }
4103    
4104                    if (orderByComparator != null) {
4105                            Object[] values = orderByComparator.getOrderByConditionValues(layout);
4106    
4107                            for (Object value : values) {
4108                                    qPos.add(value);
4109                            }
4110                    }
4111    
4112                    List<Layout> list = q.list();
4113    
4114                    if (list.size() == 2) {
4115                            return list.get(1);
4116                    }
4117                    else {
4118                            return null;
4119                    }
4120            }
4121    
4122            /**
4123             * Removes all the layouts where sourcePrototypeLayoutUuid = &#63; from the database.
4124             *
4125             * @param sourcePrototypeLayoutUuid the source prototype layout uuid
4126             */
4127            @Override
4128            public void removeBySourcePrototypeLayoutUuid(
4129                    String sourcePrototypeLayoutUuid) {
4130                    for (Layout layout : findBySourcePrototypeLayoutUuid(
4131                                    sourcePrototypeLayoutUuid, QueryUtil.ALL_POS,
4132                                    QueryUtil.ALL_POS, null)) {
4133                            remove(layout);
4134                    }
4135            }
4136    
4137            /**
4138             * Returns the number of layouts where sourcePrototypeLayoutUuid = &#63;.
4139             *
4140             * @param sourcePrototypeLayoutUuid the source prototype layout uuid
4141             * @return the number of matching layouts
4142             */
4143            @Override
4144            public int countBySourcePrototypeLayoutUuid(
4145                    String sourcePrototypeLayoutUuid) {
4146                    FinderPath finderPath = FINDER_PATH_COUNT_BY_SOURCEPROTOTYPELAYOUTUUID;
4147    
4148                    Object[] finderArgs = new Object[] { sourcePrototypeLayoutUuid };
4149    
4150                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
4151    
4152                    if (count == null) {
4153                            StringBundler query = new StringBundler(2);
4154    
4155                            query.append(_SQL_COUNT_LAYOUT_WHERE);
4156    
4157                            boolean bindSourcePrototypeLayoutUuid = false;
4158    
4159                            if (sourcePrototypeLayoutUuid == null) {
4160                                    query.append(_FINDER_COLUMN_SOURCEPROTOTYPELAYOUTUUID_SOURCEPROTOTYPELAYOUTUUID_1);
4161                            }
4162                            else if (sourcePrototypeLayoutUuid.equals(StringPool.BLANK)) {
4163                                    query.append(_FINDER_COLUMN_SOURCEPROTOTYPELAYOUTUUID_SOURCEPROTOTYPELAYOUTUUID_3);
4164                            }
4165                            else {
4166                                    bindSourcePrototypeLayoutUuid = true;
4167    
4168                                    query.append(_FINDER_COLUMN_SOURCEPROTOTYPELAYOUTUUID_SOURCEPROTOTYPELAYOUTUUID_2);
4169                            }
4170    
4171                            String sql = query.toString();
4172    
4173                            Session session = null;
4174    
4175                            try {
4176                                    session = openSession();
4177    
4178                                    Query q = session.createQuery(sql);
4179    
4180                                    QueryPos qPos = QueryPos.getInstance(q);
4181    
4182                                    if (bindSourcePrototypeLayoutUuid) {
4183                                            qPos.add(sourcePrototypeLayoutUuid);
4184                                    }
4185    
4186                                    count = (Long)q.uniqueResult();
4187    
4188                                    finderCache.putResult(finderPath, finderArgs, count);
4189                            }
4190                            catch (Exception e) {
4191                                    finderCache.removeResult(finderPath, finderArgs);
4192    
4193                                    throw processException(e);
4194                            }
4195                            finally {
4196                                    closeSession(session);
4197                            }
4198                    }
4199    
4200                    return count.intValue();
4201            }
4202    
4203            private static final String _FINDER_COLUMN_SOURCEPROTOTYPELAYOUTUUID_SOURCEPROTOTYPELAYOUTUUID_1 =
4204                    "layout.sourcePrototypeLayoutUuid IS NULL";
4205            private static final String _FINDER_COLUMN_SOURCEPROTOTYPELAYOUTUUID_SOURCEPROTOTYPELAYOUTUUID_2 =
4206                    "layout.sourcePrototypeLayoutUuid = ?";
4207            private static final String _FINDER_COLUMN_SOURCEPROTOTYPELAYOUTUUID_SOURCEPROTOTYPELAYOUTUUID_3 =
4208                    "(layout.sourcePrototypeLayoutUuid IS NULL OR layout.sourcePrototypeLayoutUuid = '')";
4209            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
4210                            LayoutModelImpl.FINDER_CACHE_ENABLED, LayoutImpl.class,
4211                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_P",
4212                            new String[] {
4213                                    Long.class.getName(), Boolean.class.getName(),
4214                                    
4215                            Integer.class.getName(), Integer.class.getName(),
4216                                    OrderByComparator.class.getName()
4217                            });
4218            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
4219                            LayoutModelImpl.FINDER_CACHE_ENABLED, LayoutImpl.class,
4220                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_P",
4221                            new String[] { Long.class.getName(), Boolean.class.getName() },
4222                            LayoutModelImpl.GROUPID_COLUMN_BITMASK |
4223                            LayoutModelImpl.PRIVATELAYOUT_COLUMN_BITMASK |
4224                            LayoutModelImpl.PARENTLAYOUTID_COLUMN_BITMASK |
4225                            LayoutModelImpl.PRIORITY_COLUMN_BITMASK);
4226            public static final FinderPath FINDER_PATH_COUNT_BY_G_P = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
4227                            LayoutModelImpl.FINDER_CACHE_ENABLED, Long.class,
4228                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P",
4229                            new String[] { Long.class.getName(), Boolean.class.getName() });
4230    
4231            /**
4232             * Returns all the layouts where groupId = &#63; and privateLayout = &#63;.
4233             *
4234             * @param groupId the group ID
4235             * @param privateLayout the private layout
4236             * @return the matching layouts
4237             */
4238            @Override
4239            public List<Layout> findByG_P(long groupId, boolean privateLayout) {
4240                    return findByG_P(groupId, privateLayout, QueryUtil.ALL_POS,
4241                            QueryUtil.ALL_POS, null);
4242            }
4243    
4244            /**
4245             * Returns a range of all the layouts where groupId = &#63; and privateLayout = &#63;.
4246             *
4247             * <p>
4248             * 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 LayoutModelImpl}. 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.
4249             * </p>
4250             *
4251             * @param groupId the group ID
4252             * @param privateLayout the private layout
4253             * @param start the lower bound of the range of layouts
4254             * @param end the upper bound of the range of layouts (not inclusive)
4255             * @return the range of matching layouts
4256             */
4257            @Override
4258            public List<Layout> findByG_P(long groupId, boolean privateLayout,
4259                    int start, int end) {
4260                    return findByG_P(groupId, privateLayout, start, end, null);
4261            }
4262    
4263            /**
4264             * Returns an ordered range of all the layouts where groupId = &#63; and privateLayout = &#63;.
4265             *
4266             * <p>
4267             * 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 LayoutModelImpl}. 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.
4268             * </p>
4269             *
4270             * @param groupId the group ID
4271             * @param privateLayout the private layout
4272             * @param start the lower bound of the range of layouts
4273             * @param end the upper bound of the range of layouts (not inclusive)
4274             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4275             * @return the ordered range of matching layouts
4276             */
4277            @Override
4278            public List<Layout> findByG_P(long groupId, boolean privateLayout,
4279                    int start, int end, OrderByComparator<Layout> orderByComparator) {
4280                    return findByG_P(groupId, privateLayout, start, end, orderByComparator,
4281                            true);
4282            }
4283    
4284            /**
4285             * Returns an ordered range of all the layouts where groupId = &#63; and privateLayout = &#63;.
4286             *
4287             * <p>
4288             * 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 LayoutModelImpl}. 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.
4289             * </p>
4290             *
4291             * @param groupId the group ID
4292             * @param privateLayout the private layout
4293             * @param start the lower bound of the range of layouts
4294             * @param end the upper bound of the range of layouts (not inclusive)
4295             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4296             * @param retrieveFromCache whether to retrieve from the finder cache
4297             * @return the ordered range of matching layouts
4298             */
4299            @Override
4300            public List<Layout> findByG_P(long groupId, boolean privateLayout,
4301                    int start, int end, OrderByComparator<Layout> orderByComparator,
4302                    boolean retrieveFromCache) {
4303                    boolean pagination = true;
4304                    FinderPath finderPath = null;
4305                    Object[] finderArgs = null;
4306    
4307                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4308                                    (orderByComparator == null)) {
4309                            pagination = false;
4310                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P;
4311                            finderArgs = new Object[] { groupId, privateLayout };
4312                    }
4313                    else {
4314                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P;
4315                            finderArgs = new Object[] {
4316                                            groupId, privateLayout,
4317                                            
4318                                            start, end, orderByComparator
4319                                    };
4320                    }
4321    
4322                    List<Layout> list = null;
4323    
4324                    if (retrieveFromCache) {
4325                            list = (List<Layout>)finderCache.getResult(finderPath, finderArgs,
4326                                            this);
4327    
4328                            if ((list != null) && !list.isEmpty()) {
4329                                    for (Layout layout : list) {
4330                                            if ((groupId != layout.getGroupId()) ||
4331                                                            (privateLayout != layout.getPrivateLayout())) {
4332                                                    list = null;
4333    
4334                                                    break;
4335                                            }
4336                                    }
4337                            }
4338                    }
4339    
4340                    if (list == null) {
4341                            StringBundler query = null;
4342    
4343                            if (orderByComparator != null) {
4344                                    query = new StringBundler(4 +
4345                                                    (orderByComparator.getOrderByFields().length * 3));
4346                            }
4347                            else {
4348                                    query = new StringBundler(4);
4349                            }
4350    
4351                            query.append(_SQL_SELECT_LAYOUT_WHERE);
4352    
4353                            query.append(_FINDER_COLUMN_G_P_GROUPID_2);
4354    
4355                            query.append(_FINDER_COLUMN_G_P_PRIVATELAYOUT_2);
4356    
4357                            if (orderByComparator != null) {
4358                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4359                                            orderByComparator);
4360                            }
4361                            else
4362                             if (pagination) {
4363                                    query.append(LayoutModelImpl.ORDER_BY_JPQL);
4364                            }
4365    
4366                            String sql = query.toString();
4367    
4368                            Session session = null;
4369    
4370                            try {
4371                                    session = openSession();
4372    
4373                                    Query q = session.createQuery(sql);
4374    
4375                                    QueryPos qPos = QueryPos.getInstance(q);
4376    
4377                                    qPos.add(groupId);
4378    
4379                                    qPos.add(privateLayout);
4380    
4381                                    if (!pagination) {
4382                                            list = (List<Layout>)QueryUtil.list(q, getDialect(), start,
4383                                                            end, false);
4384    
4385                                            Collections.sort(list);
4386    
4387                                            list = Collections.unmodifiableList(list);
4388                                    }
4389                                    else {
4390                                            list = (List<Layout>)QueryUtil.list(q, getDialect(), start,
4391                                                            end);
4392                                    }
4393    
4394                                    cacheResult(list);
4395    
4396                                    finderCache.putResult(finderPath, finderArgs, list);
4397                            }
4398                            catch (Exception e) {
4399                                    finderCache.removeResult(finderPath, finderArgs);
4400    
4401                                    throw processException(e);
4402                            }
4403                            finally {
4404                                    closeSession(session);
4405                            }
4406                    }
4407    
4408                    return list;
4409            }
4410    
4411            /**
4412             * Returns the first layout in the ordered set where groupId = &#63; and privateLayout = &#63;.
4413             *
4414             * @param groupId the group ID
4415             * @param privateLayout the private layout
4416             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4417             * @return the first matching layout
4418             * @throws NoSuchLayoutException if a matching layout could not be found
4419             */
4420            @Override
4421            public Layout findByG_P_First(long groupId, boolean privateLayout,
4422                    OrderByComparator<Layout> orderByComparator)
4423                    throws NoSuchLayoutException {
4424                    Layout layout = fetchByG_P_First(groupId, privateLayout,
4425                                    orderByComparator);
4426    
4427                    if (layout != null) {
4428                            return layout;
4429                    }
4430    
4431                    StringBundler msg = new StringBundler(6);
4432    
4433                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4434    
4435                    msg.append("groupId=");
4436                    msg.append(groupId);
4437    
4438                    msg.append(", privateLayout=");
4439                    msg.append(privateLayout);
4440    
4441                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4442    
4443                    throw new NoSuchLayoutException(msg.toString());
4444            }
4445    
4446            /**
4447             * Returns the first layout in the ordered set where groupId = &#63; and privateLayout = &#63;.
4448             *
4449             * @param groupId the group ID
4450             * @param privateLayout the private layout
4451             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4452             * @return the first matching layout, or <code>null</code> if a matching layout could not be found
4453             */
4454            @Override
4455            public Layout fetchByG_P_First(long groupId, boolean privateLayout,
4456                    OrderByComparator<Layout> orderByComparator) {
4457                    List<Layout> list = findByG_P(groupId, privateLayout, 0, 1,
4458                                    orderByComparator);
4459    
4460                    if (!list.isEmpty()) {
4461                            return list.get(0);
4462                    }
4463    
4464                    return null;
4465            }
4466    
4467            /**
4468             * Returns the last layout in the ordered set where groupId = &#63; and privateLayout = &#63;.
4469             *
4470             * @param groupId the group ID
4471             * @param privateLayout the private layout
4472             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4473             * @return the last matching layout
4474             * @throws NoSuchLayoutException if a matching layout could not be found
4475             */
4476            @Override
4477            public Layout findByG_P_Last(long groupId, boolean privateLayout,
4478                    OrderByComparator<Layout> orderByComparator)
4479                    throws NoSuchLayoutException {
4480                    Layout layout = fetchByG_P_Last(groupId, privateLayout,
4481                                    orderByComparator);
4482    
4483                    if (layout != null) {
4484                            return layout;
4485                    }
4486    
4487                    StringBundler msg = new StringBundler(6);
4488    
4489                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4490    
4491                    msg.append("groupId=");
4492                    msg.append(groupId);
4493    
4494                    msg.append(", privateLayout=");
4495                    msg.append(privateLayout);
4496    
4497                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4498    
4499                    throw new NoSuchLayoutException(msg.toString());
4500            }
4501    
4502            /**
4503             * Returns the last layout in the ordered set where groupId = &#63; and privateLayout = &#63;.
4504             *
4505             * @param groupId the group ID
4506             * @param privateLayout the private layout
4507             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4508             * @return the last matching layout, or <code>null</code> if a matching layout could not be found
4509             */
4510            @Override
4511            public Layout fetchByG_P_Last(long groupId, boolean privateLayout,
4512                    OrderByComparator<Layout> orderByComparator) {
4513                    int count = countByG_P(groupId, privateLayout);
4514    
4515                    if (count == 0) {
4516                            return null;
4517                    }
4518    
4519                    List<Layout> list = findByG_P(groupId, privateLayout, count - 1, count,
4520                                    orderByComparator);
4521    
4522                    if (!list.isEmpty()) {
4523                            return list.get(0);
4524                    }
4525    
4526                    return null;
4527            }
4528    
4529            /**
4530             * Returns the layouts before and after the current layout in the ordered set where groupId = &#63; and privateLayout = &#63;.
4531             *
4532             * @param plid the primary key of the current layout
4533             * @param groupId the group ID
4534             * @param privateLayout the private layout
4535             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4536             * @return the previous, current, and next layout
4537             * @throws NoSuchLayoutException if a layout with the primary key could not be found
4538             */
4539            @Override
4540            public Layout[] findByG_P_PrevAndNext(long plid, long groupId,
4541                    boolean privateLayout, OrderByComparator<Layout> orderByComparator)
4542                    throws NoSuchLayoutException {
4543                    Layout layout = findByPrimaryKey(plid);
4544    
4545                    Session session = null;
4546    
4547                    try {
4548                            session = openSession();
4549    
4550                            Layout[] array = new LayoutImpl[3];
4551    
4552                            array[0] = getByG_P_PrevAndNext(session, layout, groupId,
4553                                            privateLayout, orderByComparator, true);
4554    
4555                            array[1] = layout;
4556    
4557                            array[2] = getByG_P_PrevAndNext(session, layout, groupId,
4558                                            privateLayout, orderByComparator, false);
4559    
4560                            return array;
4561                    }
4562                    catch (Exception e) {
4563                            throw processException(e);
4564                    }
4565                    finally {
4566                            closeSession(session);
4567                    }
4568            }
4569    
4570            protected Layout getByG_P_PrevAndNext(Session session, Layout layout,
4571                    long groupId, boolean privateLayout,
4572                    OrderByComparator<Layout> orderByComparator, boolean previous) {
4573                    StringBundler query = null;
4574    
4575                    if (orderByComparator != null) {
4576                            query = new StringBundler(6 +
4577                                            (orderByComparator.getOrderByFields().length * 6));
4578                    }
4579                    else {
4580                            query = new StringBundler(3);
4581                    }
4582    
4583                    query.append(_SQL_SELECT_LAYOUT_WHERE);
4584    
4585                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
4586    
4587                    query.append(_FINDER_COLUMN_G_P_PRIVATELAYOUT_2);
4588    
4589                    if (orderByComparator != null) {
4590                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4591    
4592                            if (orderByConditionFields.length > 0) {
4593                                    query.append(WHERE_AND);
4594                            }
4595    
4596                            for (int i = 0; i < orderByConditionFields.length; i++) {
4597                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4598                                    query.append(orderByConditionFields[i]);
4599    
4600                                    if ((i + 1) < orderByConditionFields.length) {
4601                                            if (orderByComparator.isAscending() ^ previous) {
4602                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4603                                            }
4604                                            else {
4605                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4606                                            }
4607                                    }
4608                                    else {
4609                                            if (orderByComparator.isAscending() ^ previous) {
4610                                                    query.append(WHERE_GREATER_THAN);
4611                                            }
4612                                            else {
4613                                                    query.append(WHERE_LESSER_THAN);
4614                                            }
4615                                    }
4616                            }
4617    
4618                            query.append(ORDER_BY_CLAUSE);
4619    
4620                            String[] orderByFields = orderByComparator.getOrderByFields();
4621    
4622                            for (int i = 0; i < orderByFields.length; i++) {
4623                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4624                                    query.append(orderByFields[i]);
4625    
4626                                    if ((i + 1) < orderByFields.length) {
4627                                            if (orderByComparator.isAscending() ^ previous) {
4628                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4629                                            }
4630                                            else {
4631                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4632                                            }
4633                                    }
4634                                    else {
4635                                            if (orderByComparator.isAscending() ^ previous) {
4636                                                    query.append(ORDER_BY_ASC);
4637                                            }
4638                                            else {
4639                                                    query.append(ORDER_BY_DESC);
4640                                            }
4641                                    }
4642                            }
4643                    }
4644                    else {
4645                            query.append(LayoutModelImpl.ORDER_BY_JPQL);
4646                    }
4647    
4648                    String sql = query.toString();
4649    
4650                    Query q = session.createQuery(sql);
4651    
4652                    q.setFirstResult(0);
4653                    q.setMaxResults(2);
4654    
4655                    QueryPos qPos = QueryPos.getInstance(q);
4656    
4657                    qPos.add(groupId);
4658    
4659                    qPos.add(privateLayout);
4660    
4661                    if (orderByComparator != null) {
4662                            Object[] values = orderByComparator.getOrderByConditionValues(layout);
4663    
4664                            for (Object value : values) {
4665                                    qPos.add(value);
4666                            }
4667                    }
4668    
4669                    List<Layout> list = q.list();
4670    
4671                    if (list.size() == 2) {
4672                            return list.get(1);
4673                    }
4674                    else {
4675                            return null;
4676                    }
4677            }
4678    
4679            /**
4680             * Returns all the layouts that the user has permission to view where groupId = &#63; and privateLayout = &#63;.
4681             *
4682             * @param groupId the group ID
4683             * @param privateLayout the private layout
4684             * @return the matching layouts that the user has permission to view
4685             */
4686            @Override
4687            public List<Layout> filterFindByG_P(long groupId, boolean privateLayout) {
4688                    return filterFindByG_P(groupId, privateLayout, QueryUtil.ALL_POS,
4689                            QueryUtil.ALL_POS, null);
4690            }
4691    
4692            /**
4693             * Returns a range of all the layouts that the user has permission to view where groupId = &#63; and privateLayout = &#63;.
4694             *
4695             * <p>
4696             * 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 LayoutModelImpl}. 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.
4697             * </p>
4698             *
4699             * @param groupId the group ID
4700             * @param privateLayout the private layout
4701             * @param start the lower bound of the range of layouts
4702             * @param end the upper bound of the range of layouts (not inclusive)
4703             * @return the range of matching layouts that the user has permission to view
4704             */
4705            @Override
4706            public List<Layout> filterFindByG_P(long groupId, boolean privateLayout,
4707                    int start, int end) {
4708                    return filterFindByG_P(groupId, privateLayout, start, end, null);
4709            }
4710    
4711            /**
4712             * Returns an ordered range of all the layouts that the user has permissions to view where groupId = &#63; and privateLayout = &#63;.
4713             *
4714             * <p>
4715             * 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 LayoutModelImpl}. 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.
4716             * </p>
4717             *
4718             * @param groupId the group ID
4719             * @param privateLayout the private layout
4720             * @param start the lower bound of the range of layouts
4721             * @param end the upper bound of the range of layouts (not inclusive)
4722             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4723             * @return the ordered range of matching layouts that the user has permission to view
4724             */
4725            @Override
4726            public List<Layout> filterFindByG_P(long groupId, boolean privateLayout,
4727                    int start, int end, OrderByComparator<Layout> orderByComparator) {
4728                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4729                            return findByG_P(groupId, privateLayout, start, end,
4730                                    orderByComparator);
4731                    }
4732    
4733                    StringBundler query = null;
4734    
4735                    if (orderByComparator != null) {
4736                            query = new StringBundler(4 +
4737                                            (orderByComparator.getOrderByFields().length * 3));
4738                    }
4739                    else {
4740                            query = new StringBundler(4);
4741                    }
4742    
4743                    if (getDB().isSupportsInlineDistinct()) {
4744                            query.append(_FILTER_SQL_SELECT_LAYOUT_WHERE);
4745                    }
4746                    else {
4747                            query.append(_FILTER_SQL_SELECT_LAYOUT_NO_INLINE_DISTINCT_WHERE_1);
4748                    }
4749    
4750                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
4751    
4752                    query.append(_FINDER_COLUMN_G_P_PRIVATELAYOUT_2);
4753    
4754                    if (!getDB().isSupportsInlineDistinct()) {
4755                            query.append(_FILTER_SQL_SELECT_LAYOUT_NO_INLINE_DISTINCT_WHERE_2);
4756                    }
4757    
4758                    if (orderByComparator != null) {
4759                            if (getDB().isSupportsInlineDistinct()) {
4760                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4761                                            orderByComparator, true);
4762                            }
4763                            else {
4764                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
4765                                            orderByComparator, true);
4766                            }
4767                    }
4768                    else {
4769                            if (getDB().isSupportsInlineDistinct()) {
4770                                    query.append(LayoutModelImpl.ORDER_BY_JPQL);
4771                            }
4772                            else {
4773                                    query.append(LayoutModelImpl.ORDER_BY_SQL);
4774                            }
4775                    }
4776    
4777                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4778                                    Layout.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN,
4779                                    groupId);
4780    
4781                    Session session = null;
4782    
4783                    try {
4784                            session = openSession();
4785    
4786                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
4787    
4788                            if (getDB().isSupportsInlineDistinct()) {
4789                                    q.addEntity(_FILTER_ENTITY_ALIAS, LayoutImpl.class);
4790                            }
4791                            else {
4792                                    q.addEntity(_FILTER_ENTITY_TABLE, LayoutImpl.class);
4793                            }
4794    
4795                            QueryPos qPos = QueryPos.getInstance(q);
4796    
4797                            qPos.add(groupId);
4798    
4799                            qPos.add(privateLayout);
4800    
4801                            return (List<Layout>)QueryUtil.list(q, getDialect(), start, end);
4802                    }
4803                    catch (Exception e) {
4804                            throw processException(e);
4805                    }
4806                    finally {
4807                            closeSession(session);
4808                    }
4809            }
4810    
4811            /**
4812             * Returns the layouts before and after the current layout in the ordered set of layouts that the user has permission to view where groupId = &#63; and privateLayout = &#63;.
4813             *
4814             * @param plid the primary key of the current layout
4815             * @param groupId the group ID
4816             * @param privateLayout the private layout
4817             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4818             * @return the previous, current, and next layout
4819             * @throws NoSuchLayoutException if a layout with the primary key could not be found
4820             */
4821            @Override
4822            public Layout[] filterFindByG_P_PrevAndNext(long plid, long groupId,
4823                    boolean privateLayout, OrderByComparator<Layout> orderByComparator)
4824                    throws NoSuchLayoutException {
4825                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4826                            return findByG_P_PrevAndNext(plid, groupId, privateLayout,
4827                                    orderByComparator);
4828                    }
4829    
4830                    Layout layout = findByPrimaryKey(plid);
4831    
4832                    Session session = null;
4833    
4834                    try {
4835                            session = openSession();
4836    
4837                            Layout[] array = new LayoutImpl[3];
4838    
4839                            array[0] = filterGetByG_P_PrevAndNext(session, layout, groupId,
4840                                            privateLayout, orderByComparator, true);
4841    
4842                            array[1] = layout;
4843    
4844                            array[2] = filterGetByG_P_PrevAndNext(session, layout, groupId,
4845                                            privateLayout, orderByComparator, false);
4846    
4847                            return array;
4848                    }
4849                    catch (Exception e) {
4850                            throw processException(e);
4851                    }
4852                    finally {
4853                            closeSession(session);
4854                    }
4855            }
4856    
4857            protected Layout filterGetByG_P_PrevAndNext(Session session, Layout layout,
4858                    long groupId, boolean privateLayout,
4859                    OrderByComparator<Layout> orderByComparator, boolean previous) {
4860                    StringBundler query = null;
4861    
4862                    if (orderByComparator != null) {
4863                            query = new StringBundler(6 +
4864                                            (orderByComparator.getOrderByFields().length * 6));
4865                    }
4866                    else {
4867                            query = new StringBundler(3);
4868                    }
4869    
4870                    if (getDB().isSupportsInlineDistinct()) {
4871                            query.append(_FILTER_SQL_SELECT_LAYOUT_WHERE);
4872                    }
4873                    else {
4874                            query.append(_FILTER_SQL_SELECT_LAYOUT_NO_INLINE_DISTINCT_WHERE_1);
4875                    }
4876    
4877                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
4878    
4879                    query.append(_FINDER_COLUMN_G_P_PRIVATELAYOUT_2);
4880    
4881                    if (!getDB().isSupportsInlineDistinct()) {
4882                            query.append(_FILTER_SQL_SELECT_LAYOUT_NO_INLINE_DISTINCT_WHERE_2);
4883                    }
4884    
4885                    if (orderByComparator != null) {
4886                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4887    
4888                            if (orderByConditionFields.length > 0) {
4889                                    query.append(WHERE_AND);
4890                            }
4891    
4892                            for (int i = 0; i < orderByConditionFields.length; i++) {
4893                                    if (getDB().isSupportsInlineDistinct()) {
4894                                            query.append(_ORDER_BY_ENTITY_ALIAS);
4895                                    }
4896                                    else {
4897                                            query.append(_ORDER_BY_ENTITY_TABLE);
4898                                    }
4899    
4900                                    query.append(orderByConditionFields[i]);
4901    
4902                                    if ((i + 1) < orderByConditionFields.length) {
4903                                            if (orderByComparator.isAscending() ^ previous) {
4904                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4905                                            }
4906                                            else {
4907                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4908                                            }
4909                                    }
4910                                    else {
4911                                            if (orderByComparator.isAscending() ^ previous) {
4912                                                    query.append(WHERE_GREATER_THAN);
4913                                            }
4914                                            else {
4915                                                    query.append(WHERE_LESSER_THAN);
4916                                            }
4917                                    }
4918                            }
4919    
4920                            query.append(ORDER_BY_CLAUSE);
4921    
4922                            String[] orderByFields = orderByComparator.getOrderByFields();
4923    
4924                            for (int i = 0; i < orderByFields.length; i++) {
4925                                    if (getDB().isSupportsInlineDistinct()) {
4926                                            query.append(_ORDER_BY_ENTITY_ALIAS);
4927                                    }
4928                                    else {
4929                                            query.append(_ORDER_BY_ENTITY_TABLE);
4930                                    }
4931    
4932                                    query.append(orderByFields[i]);
4933    
4934                                    if ((i + 1) < orderByFields.length) {
4935                                            if (orderByComparator.isAscending() ^ previous) {
4936                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4937                                            }
4938                                            else {
4939                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4940                                            }
4941                                    }
4942                                    else {
4943                                            if (orderByComparator.isAscending() ^ previous) {
4944                                                    query.append(ORDER_BY_ASC);
4945                                            }
4946                                            else {
4947                                                    query.append(ORDER_BY_DESC);
4948                                            }
4949                                    }
4950                            }
4951                    }
4952                    else {
4953                            if (getDB().isSupportsInlineDistinct()) {
4954                                    query.append(LayoutModelImpl.ORDER_BY_JPQL);
4955                            }
4956                            else {
4957                                    query.append(LayoutModelImpl.ORDER_BY_SQL);
4958                            }
4959                    }
4960    
4961                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4962                                    Layout.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN,
4963                                    groupId);
4964    
4965                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
4966    
4967                    q.setFirstResult(0);
4968                    q.setMaxResults(2);
4969    
4970                    if (getDB().isSupportsInlineDistinct()) {
4971                            q.addEntity(_FILTER_ENTITY_ALIAS, LayoutImpl.class);
4972                    }
4973                    else {
4974                            q.addEntity(_FILTER_ENTITY_TABLE, LayoutImpl.class);
4975                    }
4976    
4977                    QueryPos qPos = QueryPos.getInstance(q);
4978    
4979                    qPos.add(groupId);
4980    
4981                    qPos.add(privateLayout);
4982    
4983                    if (orderByComparator != null) {
4984                            Object[] values = orderByComparator.getOrderByConditionValues(layout);
4985    
4986                            for (Object value : values) {
4987                                    qPos.add(value);
4988                            }
4989                    }
4990    
4991                    List<Layout> list = q.list();
4992    
4993                    if (list.size() == 2) {
4994                            return list.get(1);
4995                    }
4996                    else {
4997                            return null;
4998                    }
4999            }
5000    
5001            /**
5002             * Removes all the layouts where groupId = &#63; and privateLayout = &#63; from the database.
5003             *
5004             * @param groupId the group ID
5005             * @param privateLayout the private layout
5006             */
5007            @Override
5008            public void removeByG_P(long groupId, boolean privateLayout) {
5009                    for (Layout layout : findByG_P(groupId, privateLayout,
5010                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
5011                            remove(layout);
5012                    }
5013            }
5014    
5015            /**
5016             * Returns the number of layouts where groupId = &#63; and privateLayout = &#63;.
5017             *
5018             * @param groupId the group ID
5019             * @param privateLayout the private layout
5020             * @return the number of matching layouts
5021             */
5022            @Override
5023            public int countByG_P(long groupId, boolean privateLayout) {
5024                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_P;
5025    
5026                    Object[] finderArgs = new Object[] { groupId, privateLayout };
5027    
5028                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
5029    
5030                    if (count == null) {
5031                            StringBundler query = new StringBundler(3);
5032    
5033                            query.append(_SQL_COUNT_LAYOUT_WHERE);
5034    
5035                            query.append(_FINDER_COLUMN_G_P_GROUPID_2);
5036    
5037                            query.append(_FINDER_COLUMN_G_P_PRIVATELAYOUT_2);
5038    
5039                            String sql = query.toString();
5040    
5041                            Session session = null;
5042    
5043                            try {
5044                                    session = openSession();
5045    
5046                                    Query q = session.createQuery(sql);
5047    
5048                                    QueryPos qPos = QueryPos.getInstance(q);
5049    
5050                                    qPos.add(groupId);
5051    
5052                                    qPos.add(privateLayout);
5053    
5054                                    count = (Long)q.uniqueResult();
5055    
5056                                    finderCache.putResult(finderPath, finderArgs, count);
5057                            }
5058                            catch (Exception e) {
5059                                    finderCache.removeResult(finderPath, finderArgs);
5060    
5061                                    throw processException(e);
5062                            }
5063                            finally {
5064                                    closeSession(session);
5065                            }
5066                    }
5067    
5068                    return count.intValue();
5069            }
5070    
5071            /**
5072             * Returns the number of layouts that the user has permission to view where groupId = &#63; and privateLayout = &#63;.
5073             *
5074             * @param groupId the group ID
5075             * @param privateLayout the private layout
5076             * @return the number of matching layouts that the user has permission to view
5077             */
5078            @Override
5079            public int filterCountByG_P(long groupId, boolean privateLayout) {
5080                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5081                            return countByG_P(groupId, privateLayout);
5082                    }
5083    
5084                    StringBundler query = new StringBundler(3);
5085    
5086                    query.append(_FILTER_SQL_COUNT_LAYOUT_WHERE);
5087    
5088                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
5089    
5090                    query.append(_FINDER_COLUMN_G_P_PRIVATELAYOUT_2);
5091    
5092                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5093                                    Layout.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN,
5094                                    groupId);
5095    
5096                    Session session = null;
5097    
5098                    try {
5099                            session = openSession();
5100    
5101                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
5102    
5103                            q.addScalar(COUNT_COLUMN_NAME,
5104                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
5105    
5106                            QueryPos qPos = QueryPos.getInstance(q);
5107    
5108                            qPos.add(groupId);
5109    
5110                            qPos.add(privateLayout);
5111    
5112                            Long count = (Long)q.uniqueResult();
5113    
5114                            return count.intValue();
5115                    }
5116                    catch (Exception e) {
5117                            throw processException(e);
5118                    }
5119                    finally {
5120                            closeSession(session);
5121                    }
5122            }
5123    
5124            private static final String _FINDER_COLUMN_G_P_GROUPID_2 = "layout.groupId = ? AND ";
5125            private static final String _FINDER_COLUMN_G_P_PRIVATELAYOUT_2 = "layout.privateLayout = ?";
5126            public static final FinderPath FINDER_PATH_FETCH_BY_G_P_L = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
5127                            LayoutModelImpl.FINDER_CACHE_ENABLED, LayoutImpl.class,
5128                            FINDER_CLASS_NAME_ENTITY, "fetchByG_P_L",
5129                            new String[] {
5130                                    Long.class.getName(), Boolean.class.getName(),
5131                                    Long.class.getName()
5132                            },
5133                            LayoutModelImpl.GROUPID_COLUMN_BITMASK |
5134                            LayoutModelImpl.PRIVATELAYOUT_COLUMN_BITMASK |
5135                            LayoutModelImpl.LAYOUTID_COLUMN_BITMASK);
5136            public static final FinderPath FINDER_PATH_COUNT_BY_G_P_L = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
5137                            LayoutModelImpl.FINDER_CACHE_ENABLED, Long.class,
5138                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P_L",
5139                            new String[] {
5140                                    Long.class.getName(), Boolean.class.getName(),
5141                                    Long.class.getName()
5142                            });
5143    
5144            /**
5145             * Returns the layout where groupId = &#63; and privateLayout = &#63; and layoutId = &#63; or throws a {@link NoSuchLayoutException} if it could not be found.
5146             *
5147             * @param groupId the group ID
5148             * @param privateLayout the private layout
5149             * @param layoutId the layout ID
5150             * @return the matching layout
5151             * @throws NoSuchLayoutException if a matching layout could not be found
5152             */
5153            @Override
5154            public Layout findByG_P_L(long groupId, boolean privateLayout, long layoutId)
5155                    throws NoSuchLayoutException {
5156                    Layout layout = fetchByG_P_L(groupId, privateLayout, layoutId);
5157    
5158                    if (layout == null) {
5159                            StringBundler msg = new StringBundler(8);
5160    
5161                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5162    
5163                            msg.append("groupId=");
5164                            msg.append(groupId);
5165    
5166                            msg.append(", privateLayout=");
5167                            msg.append(privateLayout);
5168    
5169                            msg.append(", layoutId=");
5170                            msg.append(layoutId);
5171    
5172                            msg.append(StringPool.CLOSE_CURLY_BRACE);
5173    
5174                            if (_log.isWarnEnabled()) {
5175                                    _log.warn(msg.toString());
5176                            }
5177    
5178                            throw new NoSuchLayoutException(msg.toString());
5179                    }
5180    
5181                    return layout;
5182            }
5183    
5184            /**
5185             * Returns the layout where groupId = &#63; and privateLayout = &#63; and layoutId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
5186             *
5187             * @param groupId the group ID
5188             * @param privateLayout the private layout
5189             * @param layoutId the layout ID
5190             * @return the matching layout, or <code>null</code> if a matching layout could not be found
5191             */
5192            @Override
5193            public Layout fetchByG_P_L(long groupId, boolean privateLayout,
5194                    long layoutId) {
5195                    return fetchByG_P_L(groupId, privateLayout, layoutId, true);
5196            }
5197    
5198            /**
5199             * Returns the layout where groupId = &#63; and privateLayout = &#63; and layoutId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
5200             *
5201             * @param groupId the group ID
5202             * @param privateLayout the private layout
5203             * @param layoutId the layout ID
5204             * @param retrieveFromCache whether to retrieve from the finder cache
5205             * @return the matching layout, or <code>null</code> if a matching layout could not be found
5206             */
5207            @Override
5208            public Layout fetchByG_P_L(long groupId, boolean privateLayout,
5209                    long layoutId, boolean retrieveFromCache) {
5210                    Object[] finderArgs = new Object[] { groupId, privateLayout, layoutId };
5211    
5212                    Object result = null;
5213    
5214                    if (retrieveFromCache) {
5215                            result = finderCache.getResult(FINDER_PATH_FETCH_BY_G_P_L,
5216                                            finderArgs, this);
5217                    }
5218    
5219                    if (result instanceof Layout) {
5220                            Layout layout = (Layout)result;
5221    
5222                            if ((groupId != layout.getGroupId()) ||
5223                                            (privateLayout != layout.getPrivateLayout()) ||
5224                                            (layoutId != layout.getLayoutId())) {
5225                                    result = null;
5226                            }
5227                    }
5228    
5229                    if (result == null) {
5230                            StringBundler query = new StringBundler(5);
5231    
5232                            query.append(_SQL_SELECT_LAYOUT_WHERE);
5233    
5234                            query.append(_FINDER_COLUMN_G_P_L_GROUPID_2);
5235    
5236                            query.append(_FINDER_COLUMN_G_P_L_PRIVATELAYOUT_2);
5237    
5238                            query.append(_FINDER_COLUMN_G_P_L_LAYOUTID_2);
5239    
5240                            String sql = query.toString();
5241    
5242                            Session session = null;
5243    
5244                            try {
5245                                    session = openSession();
5246    
5247                                    Query q = session.createQuery(sql);
5248    
5249                                    QueryPos qPos = QueryPos.getInstance(q);
5250    
5251                                    qPos.add(groupId);
5252    
5253                                    qPos.add(privateLayout);
5254    
5255                                    qPos.add(layoutId);
5256    
5257                                    List<Layout> list = q.list();
5258    
5259                                    if (list.isEmpty()) {
5260                                            finderCache.putResult(FINDER_PATH_FETCH_BY_G_P_L,
5261                                                    finderArgs, list);
5262                                    }
5263                                    else {
5264                                            Layout layout = list.get(0);
5265    
5266                                            result = layout;
5267    
5268                                            cacheResult(layout);
5269    
5270                                            if ((layout.getGroupId() != groupId) ||
5271                                                            (layout.getPrivateLayout() != privateLayout) ||
5272                                                            (layout.getLayoutId() != layoutId)) {
5273                                                    finderCache.putResult(FINDER_PATH_FETCH_BY_G_P_L,
5274                                                            finderArgs, layout);
5275                                            }
5276                                    }
5277                            }
5278                            catch (Exception e) {
5279                                    finderCache.removeResult(FINDER_PATH_FETCH_BY_G_P_L, finderArgs);
5280    
5281                                    throw processException(e);
5282                            }
5283                            finally {
5284                                    closeSession(session);
5285                            }
5286                    }
5287    
5288                    if (result instanceof List<?>) {
5289                            return null;
5290                    }
5291                    else {
5292                            return (Layout)result;
5293                    }
5294            }
5295    
5296            /**
5297             * Removes the layout where groupId = &#63; and privateLayout = &#63; and layoutId = &#63; from the database.
5298             *
5299             * @param groupId the group ID
5300             * @param privateLayout the private layout
5301             * @param layoutId the layout ID
5302             * @return the layout that was removed
5303             */
5304            @Override
5305            public Layout removeByG_P_L(long groupId, boolean privateLayout,
5306                    long layoutId) throws NoSuchLayoutException {
5307                    Layout layout = findByG_P_L(groupId, privateLayout, layoutId);
5308    
5309                    return remove(layout);
5310            }
5311    
5312            /**
5313             * Returns the number of layouts where groupId = &#63; and privateLayout = &#63; and layoutId = &#63;.
5314             *
5315             * @param groupId the group ID
5316             * @param privateLayout the private layout
5317             * @param layoutId the layout ID
5318             * @return the number of matching layouts
5319             */
5320            @Override
5321            public int countByG_P_L(long groupId, boolean privateLayout, long layoutId) {
5322                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_P_L;
5323    
5324                    Object[] finderArgs = new Object[] { groupId, privateLayout, layoutId };
5325    
5326                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
5327    
5328                    if (count == null) {
5329                            StringBundler query = new StringBundler(4);
5330    
5331                            query.append(_SQL_COUNT_LAYOUT_WHERE);
5332    
5333                            query.append(_FINDER_COLUMN_G_P_L_GROUPID_2);
5334    
5335                            query.append(_FINDER_COLUMN_G_P_L_PRIVATELAYOUT_2);
5336    
5337                            query.append(_FINDER_COLUMN_G_P_L_LAYOUTID_2);
5338    
5339                            String sql = query.toString();
5340    
5341                            Session session = null;
5342    
5343                            try {
5344                                    session = openSession();
5345    
5346                                    Query q = session.createQuery(sql);
5347    
5348                                    QueryPos qPos = QueryPos.getInstance(q);
5349    
5350                                    qPos.add(groupId);
5351    
5352                                    qPos.add(privateLayout);
5353    
5354                                    qPos.add(layoutId);
5355    
5356                                    count = (Long)q.uniqueResult();
5357    
5358                                    finderCache.putResult(finderPath, finderArgs, count);
5359                            }
5360                            catch (Exception e) {
5361                                    finderCache.removeResult(finderPath, finderArgs);
5362    
5363                                    throw processException(e);
5364                            }
5365                            finally {
5366                                    closeSession(session);
5367                            }
5368                    }
5369    
5370                    return count.intValue();
5371            }
5372    
5373            private static final String _FINDER_COLUMN_G_P_L_GROUPID_2 = "layout.groupId = ? AND ";
5374            private static final String _FINDER_COLUMN_G_P_L_PRIVATELAYOUT_2 = "layout.privateLayout = ? AND ";
5375            private static final String _FINDER_COLUMN_G_P_L_LAYOUTID_2 = "layout.layoutId = ?";
5376            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_P = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
5377                            LayoutModelImpl.FINDER_CACHE_ENABLED, LayoutImpl.class,
5378                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_P_P",
5379                            new String[] {
5380                                    Long.class.getName(), Boolean.class.getName(),
5381                                    Long.class.getName(),
5382                                    
5383                            Integer.class.getName(), Integer.class.getName(),
5384                                    OrderByComparator.class.getName()
5385                            });
5386            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_P = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
5387                            LayoutModelImpl.FINDER_CACHE_ENABLED, LayoutImpl.class,
5388                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_P_P",
5389                            new String[] {
5390                                    Long.class.getName(), Boolean.class.getName(),
5391                                    Long.class.getName()
5392                            },
5393                            LayoutModelImpl.GROUPID_COLUMN_BITMASK |
5394                            LayoutModelImpl.PRIVATELAYOUT_COLUMN_BITMASK |
5395                            LayoutModelImpl.PARENTLAYOUTID_COLUMN_BITMASK |
5396                            LayoutModelImpl.PRIORITY_COLUMN_BITMASK);
5397            public static final FinderPath FINDER_PATH_COUNT_BY_G_P_P = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
5398                            LayoutModelImpl.FINDER_CACHE_ENABLED, Long.class,
5399                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P_P",
5400                            new String[] {
5401                                    Long.class.getName(), Boolean.class.getName(),
5402                                    Long.class.getName()
5403                            });
5404    
5405            /**
5406             * Returns all the layouts where groupId = &#63; and privateLayout = &#63; and parentLayoutId = &#63;.
5407             *
5408             * @param groupId the group ID
5409             * @param privateLayout the private layout
5410             * @param parentLayoutId the parent layout ID
5411             * @return the matching layouts
5412             */
5413            @Override
5414            public List<Layout> findByG_P_P(long groupId, boolean privateLayout,
5415                    long parentLayoutId) {
5416                    return findByG_P_P(groupId, privateLayout, parentLayoutId,
5417                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
5418            }
5419    
5420            /**
5421             * Returns a range of all the layouts where groupId = &#63; and privateLayout = &#63; and parentLayoutId = &#63;.
5422             *
5423             * <p>
5424             * 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 LayoutModelImpl}. 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.
5425             * </p>
5426             *
5427             * @param groupId the group ID
5428             * @param privateLayout the private layout
5429             * @param parentLayoutId the parent layout ID
5430             * @param start the lower bound of the range of layouts
5431             * @param end the upper bound of the range of layouts (not inclusive)
5432             * @return the range of matching layouts
5433             */
5434            @Override
5435            public List<Layout> findByG_P_P(long groupId, boolean privateLayout,
5436                    long parentLayoutId, int start, int end) {
5437                    return findByG_P_P(groupId, privateLayout, parentLayoutId, start, end,
5438                            null);
5439            }
5440    
5441            /**
5442             * Returns an ordered range of all the layouts where groupId = &#63; and privateLayout = &#63; and parentLayoutId = &#63;.
5443             *
5444             * <p>
5445             * 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 LayoutModelImpl}. 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.
5446             * </p>
5447             *
5448             * @param groupId the group ID
5449             * @param privateLayout the private layout
5450             * @param parentLayoutId the parent layout ID
5451             * @param start the lower bound of the range of layouts
5452             * @param end the upper bound of the range of layouts (not inclusive)
5453             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5454             * @return the ordered range of matching layouts
5455             */
5456            @Override
5457            public List<Layout> findByG_P_P(long groupId, boolean privateLayout,
5458                    long parentLayoutId, int start, int end,
5459                    OrderByComparator<Layout> orderByComparator) {
5460                    return findByG_P_P(groupId, privateLayout, parentLayoutId, start, end,
5461                            orderByComparator, true);
5462            }
5463    
5464            /**
5465             * Returns an ordered range of all the layouts where groupId = &#63; and privateLayout = &#63; and parentLayoutId = &#63;.
5466             *
5467             * <p>
5468             * 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 LayoutModelImpl}. 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.
5469             * </p>
5470             *
5471             * @param groupId the group ID
5472             * @param privateLayout the private layout
5473             * @param parentLayoutId the parent layout ID
5474             * @param start the lower bound of the range of layouts
5475             * @param end the upper bound of the range of layouts (not inclusive)
5476             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5477             * @param retrieveFromCache whether to retrieve from the finder cache
5478             * @return the ordered range of matching layouts
5479             */
5480            @Override
5481            public List<Layout> findByG_P_P(long groupId, boolean privateLayout,
5482                    long parentLayoutId, int start, int end,
5483                    OrderByComparator<Layout> orderByComparator, boolean retrieveFromCache) {
5484                    boolean pagination = true;
5485                    FinderPath finderPath = null;
5486                    Object[] finderArgs = null;
5487    
5488                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5489                                    (orderByComparator == null)) {
5490                            pagination = false;
5491                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_P;
5492                            finderArgs = new Object[] { groupId, privateLayout, parentLayoutId };
5493                    }
5494                    else {
5495                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_P;
5496                            finderArgs = new Object[] {
5497                                            groupId, privateLayout, parentLayoutId,
5498                                            
5499                                            start, end, orderByComparator
5500                                    };
5501                    }
5502    
5503                    List<Layout> list = null;
5504    
5505                    if (retrieveFromCache) {
5506                            list = (List<Layout>)finderCache.getResult(finderPath, finderArgs,
5507                                            this);
5508    
5509                            if ((list != null) && !list.isEmpty()) {
5510                                    for (Layout layout : list) {
5511                                            if ((groupId != layout.getGroupId()) ||
5512                                                            (privateLayout != layout.getPrivateLayout()) ||
5513                                                            (parentLayoutId != layout.getParentLayoutId())) {
5514                                                    list = null;
5515    
5516                                                    break;
5517                                            }
5518                                    }
5519                            }
5520                    }
5521    
5522                    if (list == null) {
5523                            StringBundler query = null;
5524    
5525                            if (orderByComparator != null) {
5526                                    query = new StringBundler(5 +
5527                                                    (orderByComparator.getOrderByFields().length * 3));
5528                            }
5529                            else {
5530                                    query = new StringBundler(5);
5531                            }
5532    
5533                            query.append(_SQL_SELECT_LAYOUT_WHERE);
5534    
5535                            query.append(_FINDER_COLUMN_G_P_P_GROUPID_2);
5536    
5537                            query.append(_FINDER_COLUMN_G_P_P_PRIVATELAYOUT_2);
5538    
5539                            query.append(_FINDER_COLUMN_G_P_P_PARENTLAYOUTID_2);
5540    
5541                            if (orderByComparator != null) {
5542                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5543                                            orderByComparator);
5544                            }
5545                            else
5546                             if (pagination) {
5547                                    query.append(LayoutModelImpl.ORDER_BY_JPQL);
5548                            }
5549    
5550                            String sql = query.toString();
5551    
5552                            Session session = null;
5553    
5554                            try {
5555                                    session = openSession();
5556    
5557                                    Query q = session.createQuery(sql);
5558    
5559                                    QueryPos qPos = QueryPos.getInstance(q);
5560    
5561                                    qPos.add(groupId);
5562    
5563                                    qPos.add(privateLayout);
5564    
5565                                    qPos.add(parentLayoutId);
5566    
5567                                    if (!pagination) {
5568                                            list = (List<Layout>)QueryUtil.list(q, getDialect(), start,
5569                                                            end, false);
5570    
5571                                            Collections.sort(list);
5572    
5573                                            list = Collections.unmodifiableList(list);
5574                                    }
5575                                    else {
5576                                            list = (List<Layout>)QueryUtil.list(q, getDialect(), start,
5577                                                            end);
5578                                    }
5579    
5580                                    cacheResult(list);
5581    
5582                                    finderCache.putResult(finderPath, finderArgs, list);
5583                            }
5584                            catch (Exception e) {
5585                                    finderCache.removeResult(finderPath, finderArgs);
5586    
5587                                    throw processException(e);
5588                            }
5589                            finally {
5590                                    closeSession(session);
5591                            }
5592                    }
5593    
5594                    return list;
5595            }
5596    
5597            /**
5598             * Returns the first layout in the ordered set where groupId = &#63; and privateLayout = &#63; and parentLayoutId = &#63;.
5599             *
5600             * @param groupId the group ID
5601             * @param privateLayout the private layout
5602             * @param parentLayoutId the parent layout ID
5603             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5604             * @return the first matching layout
5605             * @throws NoSuchLayoutException if a matching layout could not be found
5606             */
5607            @Override
5608            public Layout findByG_P_P_First(long groupId, boolean privateLayout,
5609                    long parentLayoutId, OrderByComparator<Layout> orderByComparator)
5610                    throws NoSuchLayoutException {
5611                    Layout layout = fetchByG_P_P_First(groupId, privateLayout,
5612                                    parentLayoutId, orderByComparator);
5613    
5614                    if (layout != null) {
5615                            return layout;
5616                    }
5617    
5618                    StringBundler msg = new StringBundler(8);
5619    
5620                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5621    
5622                    msg.append("groupId=");
5623                    msg.append(groupId);
5624    
5625                    msg.append(", privateLayout=");
5626                    msg.append(privateLayout);
5627    
5628                    msg.append(", parentLayoutId=");
5629                    msg.append(parentLayoutId);
5630    
5631                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5632    
5633                    throw new NoSuchLayoutException(msg.toString());
5634            }
5635    
5636            /**
5637             * Returns the first layout in the ordered set where groupId = &#63; and privateLayout = &#63; and parentLayoutId = &#63;.
5638             *
5639             * @param groupId the group ID
5640             * @param privateLayout the private layout
5641             * @param parentLayoutId the parent layout ID
5642             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5643             * @return the first matching layout, or <code>null</code> if a matching layout could not be found
5644             */
5645            @Override
5646            public Layout fetchByG_P_P_First(long groupId, boolean privateLayout,
5647                    long parentLayoutId, OrderByComparator<Layout> orderByComparator) {
5648                    List<Layout> list = findByG_P_P(groupId, privateLayout, parentLayoutId,
5649                                    0, 1, orderByComparator);
5650    
5651                    if (!list.isEmpty()) {
5652                            return list.get(0);
5653                    }
5654    
5655                    return null;
5656            }
5657    
5658            /**
5659             * Returns the last layout in the ordered set where groupId = &#63; and privateLayout = &#63; and parentLayoutId = &#63;.
5660             *
5661             * @param groupId the group ID
5662             * @param privateLayout the private layout
5663             * @param parentLayoutId the parent layout ID
5664             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5665             * @return the last matching layout
5666             * @throws NoSuchLayoutException if a matching layout could not be found
5667             */
5668            @Override
5669            public Layout findByG_P_P_Last(long groupId, boolean privateLayout,
5670                    long parentLayoutId, OrderByComparator<Layout> orderByComparator)
5671                    throws NoSuchLayoutException {
5672                    Layout layout = fetchByG_P_P_Last(groupId, privateLayout,
5673                                    parentLayoutId, orderByComparator);
5674    
5675                    if (layout != null) {
5676                            return layout;
5677                    }
5678    
5679                    StringBundler msg = new StringBundler(8);
5680    
5681                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5682    
5683                    msg.append("groupId=");
5684                    msg.append(groupId);
5685    
5686                    msg.append(", privateLayout=");
5687                    msg.append(privateLayout);
5688    
5689                    msg.append(", parentLayoutId=");
5690                    msg.append(parentLayoutId);
5691    
5692                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5693    
5694                    throw new NoSuchLayoutException(msg.toString());
5695            }
5696    
5697            /**
5698             * Returns the last layout in the ordered set where groupId = &#63; and privateLayout = &#63; and parentLayoutId = &#63;.
5699             *
5700             * @param groupId the group ID
5701             * @param privateLayout the private layout
5702             * @param parentLayoutId the parent layout ID
5703             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5704             * @return the last matching layout, or <code>null</code> if a matching layout could not be found
5705             */
5706            @Override
5707            public Layout fetchByG_P_P_Last(long groupId, boolean privateLayout,
5708                    long parentLayoutId, OrderByComparator<Layout> orderByComparator) {
5709                    int count = countByG_P_P(groupId, privateLayout, parentLayoutId);
5710    
5711                    if (count == 0) {
5712                            return null;
5713                    }
5714    
5715                    List<Layout> list = findByG_P_P(groupId, privateLayout, parentLayoutId,
5716                                    count - 1, count, orderByComparator);
5717    
5718                    if (!list.isEmpty()) {
5719                            return list.get(0);
5720                    }
5721    
5722                    return null;
5723            }
5724    
5725            /**
5726             * Returns the layouts before and after the current layout in the ordered set where groupId = &#63; and privateLayout = &#63; and parentLayoutId = &#63;.
5727             *
5728             * @param plid the primary key of the current layout
5729             * @param groupId the group ID
5730             * @param privateLayout the private layout
5731             * @param parentLayoutId the parent layout ID
5732             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5733             * @return the previous, current, and next layout
5734             * @throws NoSuchLayoutException if a layout with the primary key could not be found
5735             */
5736            @Override
5737            public Layout[] findByG_P_P_PrevAndNext(long plid, long groupId,
5738                    boolean privateLayout, long parentLayoutId,
5739                    OrderByComparator<Layout> orderByComparator)
5740                    throws NoSuchLayoutException {
5741                    Layout layout = findByPrimaryKey(plid);
5742    
5743                    Session session = null;
5744    
5745                    try {
5746                            session = openSession();
5747    
5748                            Layout[] array = new LayoutImpl[3];
5749    
5750                            array[0] = getByG_P_P_PrevAndNext(session, layout, groupId,
5751                                            privateLayout, parentLayoutId, orderByComparator, true);
5752    
5753                            array[1] = layout;
5754    
5755                            array[2] = getByG_P_P_PrevAndNext(session, layout, groupId,
5756                                            privateLayout, parentLayoutId, orderByComparator, false);
5757    
5758                            return array;
5759                    }
5760                    catch (Exception e) {
5761                            throw processException(e);
5762                    }
5763                    finally {
5764                            closeSession(session);
5765                    }
5766            }
5767    
5768            protected Layout getByG_P_P_PrevAndNext(Session session, Layout layout,
5769                    long groupId, boolean privateLayout, long parentLayoutId,
5770                    OrderByComparator<Layout> orderByComparator, boolean previous) {
5771                    StringBundler query = null;
5772    
5773                    if (orderByComparator != null) {
5774                            query = new StringBundler(6 +
5775                                            (orderByComparator.getOrderByFields().length * 6));
5776                    }
5777                    else {
5778                            query = new StringBundler(3);
5779                    }
5780    
5781                    query.append(_SQL_SELECT_LAYOUT_WHERE);
5782    
5783                    query.append(_FINDER_COLUMN_G_P_P_GROUPID_2);
5784    
5785                    query.append(_FINDER_COLUMN_G_P_P_PRIVATELAYOUT_2);
5786    
5787                    query.append(_FINDER_COLUMN_G_P_P_PARENTLAYOUTID_2);
5788    
5789                    if (orderByComparator != null) {
5790                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5791    
5792                            if (orderByConditionFields.length > 0) {
5793                                    query.append(WHERE_AND);
5794                            }
5795    
5796                            for (int i = 0; i < orderByConditionFields.length; i++) {
5797                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5798                                    query.append(orderByConditionFields[i]);
5799    
5800                                    if ((i + 1) < orderByConditionFields.length) {
5801                                            if (orderByComparator.isAscending() ^ previous) {
5802                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5803                                            }
5804                                            else {
5805                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5806                                            }
5807                                    }
5808                                    else {
5809                                            if (orderByComparator.isAscending() ^ previous) {
5810                                                    query.append(WHERE_GREATER_THAN);
5811                                            }
5812                                            else {
5813                                                    query.append(WHERE_LESSER_THAN);
5814                                            }
5815                                    }
5816                            }
5817    
5818                            query.append(ORDER_BY_CLAUSE);
5819    
5820                            String[] orderByFields = orderByComparator.getOrderByFields();
5821    
5822                            for (int i = 0; i < orderByFields.length; i++) {
5823                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5824                                    query.append(orderByFields[i]);
5825    
5826                                    if ((i + 1) < orderByFields.length) {
5827                                            if (orderByComparator.isAscending() ^ previous) {
5828                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5829                                            }
5830                                            else {
5831                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5832                                            }
5833                                    }
5834                                    else {
5835                                            if (orderByComparator.isAscending() ^ previous) {
5836                                                    query.append(ORDER_BY_ASC);
5837                                            }
5838                                            else {
5839                                                    query.append(ORDER_BY_DESC);
5840                                            }
5841                                    }
5842                            }
5843                    }
5844                    else {
5845                            query.append(LayoutModelImpl.ORDER_BY_JPQL);
5846                    }
5847    
5848                    String sql = query.toString();
5849    
5850                    Query q = session.createQuery(sql);
5851    
5852                    q.setFirstResult(0);
5853                    q.setMaxResults(2);
5854    
5855                    QueryPos qPos = QueryPos.getInstance(q);
5856    
5857                    qPos.add(groupId);
5858    
5859                    qPos.add(privateLayout);
5860    
5861                    qPos.add(parentLayoutId);
5862    
5863                    if (orderByComparator != null) {
5864                            Object[] values = orderByComparator.getOrderByConditionValues(layout);
5865    
5866                            for (Object value : values) {
5867                                    qPos.add(value);
5868                            }
5869                    }
5870    
5871                    List<Layout> list = q.list();
5872    
5873                    if (list.size() == 2) {
5874                            return list.get(1);
5875                    }
5876                    else {
5877                            return null;
5878                    }
5879            }
5880    
5881            /**
5882             * Returns all the layouts that the user has permission to view where groupId = &#63; and privateLayout = &#63; and parentLayoutId = &#63;.
5883             *
5884             * @param groupId the group ID
5885             * @param privateLayout the private layout
5886             * @param parentLayoutId the parent layout ID
5887             * @return the matching layouts that the user has permission to view
5888             */
5889            @Override
5890            public List<Layout> filterFindByG_P_P(long groupId, boolean privateLayout,
5891                    long parentLayoutId) {
5892                    return filterFindByG_P_P(groupId, privateLayout, parentLayoutId,
5893                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
5894            }
5895    
5896            /**
5897             * Returns a range of all the layouts that the user has permission to view where groupId = &#63; and privateLayout = &#63; and parentLayoutId = &#63;.
5898             *
5899             * <p>
5900             * 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 LayoutModelImpl}. 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.
5901             * </p>
5902             *
5903             * @param groupId the group ID
5904             * @param privateLayout the private layout
5905             * @param parentLayoutId the parent layout ID
5906             * @param start the lower bound of the range of layouts
5907             * @param end the upper bound of the range of layouts (not inclusive)
5908             * @return the range of matching layouts that the user has permission to view
5909             */
5910            @Override
5911            public List<Layout> filterFindByG_P_P(long groupId, boolean privateLayout,
5912                    long parentLayoutId, int start, int end) {
5913                    return filterFindByG_P_P(groupId, privateLayout, parentLayoutId, start,
5914                            end, null);
5915            }
5916    
5917            /**
5918             * Returns an ordered range of all the layouts that the user has permissions to view where groupId = &#63; and privateLayout = &#63; and parentLayoutId = &#63;.
5919             *
5920             * <p>
5921             * 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 LayoutModelImpl}. 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.
5922             * </p>
5923             *
5924             * @param groupId the group ID
5925             * @param privateLayout the private layout
5926             * @param parentLayoutId the parent layout ID
5927             * @param start the lower bound of the range of layouts
5928             * @param end the upper bound of the range of layouts (not inclusive)
5929             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5930             * @return the ordered range of matching layouts that the user has permission to view
5931             */
5932            @Override
5933            public List<Layout> filterFindByG_P_P(long groupId, boolean privateLayout,
5934                    long parentLayoutId, int start, int end,
5935                    OrderByComparator<Layout> orderByComparator) {
5936                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5937                            return findByG_P_P(groupId, privateLayout, parentLayoutId, start,
5938                                    end, orderByComparator);
5939                    }
5940    
5941                    StringBundler query = null;
5942    
5943                    if (orderByComparator != null) {
5944                            query = new StringBundler(5 +
5945                                            (orderByComparator.getOrderByFields().length * 3));
5946                    }
5947                    else {
5948                            query = new StringBundler(5);
5949                    }
5950    
5951                    if (getDB().isSupportsInlineDistinct()) {
5952                            query.append(_FILTER_SQL_SELECT_LAYOUT_WHERE);
5953                    }
5954                    else {
5955                            query.append(_FILTER_SQL_SELECT_LAYOUT_NO_INLINE_DISTINCT_WHERE_1);
5956                    }
5957    
5958                    query.append(_FINDER_COLUMN_G_P_P_GROUPID_2);
5959    
5960                    query.append(_FINDER_COLUMN_G_P_P_PRIVATELAYOUT_2);
5961    
5962                    query.append(_FINDER_COLUMN_G_P_P_PARENTLAYOUTID_2);
5963    
5964                    if (!getDB().isSupportsInlineDistinct()) {
5965                            query.append(_FILTER_SQL_SELECT_LAYOUT_NO_INLINE_DISTINCT_WHERE_2);
5966                    }
5967    
5968                    if (orderByComparator != null) {
5969                            if (getDB().isSupportsInlineDistinct()) {
5970                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5971                                            orderByComparator, true);
5972                            }
5973                            else {
5974                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
5975                                            orderByComparator, true);
5976                            }
5977                    }
5978                    else {
5979                            if (getDB().isSupportsInlineDistinct()) {
5980                                    query.append(LayoutModelImpl.ORDER_BY_JPQL);
5981                            }
5982                            else {
5983                                    query.append(LayoutModelImpl.ORDER_BY_SQL);
5984                            }
5985                    }
5986    
5987                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5988                                    Layout.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN,
5989                                    groupId);
5990    
5991                    Session session = null;
5992    
5993                    try {
5994                            session = openSession();
5995    
5996                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
5997    
5998                            if (getDB().isSupportsInlineDistinct()) {
5999                                    q.addEntity(_FILTER_ENTITY_ALIAS, LayoutImpl.class);
6000                            }
6001                            else {
6002                                    q.addEntity(_FILTER_ENTITY_TABLE, LayoutImpl.class);
6003                            }
6004    
6005                            QueryPos qPos = QueryPos.getInstance(q);
6006    
6007                            qPos.add(groupId);
6008    
6009                            qPos.add(privateLayout);
6010    
6011                            qPos.add(parentLayoutId);
6012    
6013                            return (List<Layout>)QueryUtil.list(q, getDialect(), start, end);
6014                    }
6015                    catch (Exception e) {
6016                            throw processException(e);
6017                    }
6018                    finally {
6019                            closeSession(session);
6020                    }
6021            }
6022    
6023            /**
6024             * Returns the layouts before and after the current layout in the ordered set of layouts that the user has permission to view where groupId = &#63; and privateLayout = &#63; and parentLayoutId = &#63;.
6025             *
6026             * @param plid the primary key of the current layout
6027             * @param groupId the group ID
6028             * @param privateLayout the private layout
6029             * @param parentLayoutId the parent layout ID
6030             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6031             * @return the previous, current, and next layout
6032             * @throws NoSuchLayoutException if a layout with the primary key could not be found
6033             */
6034            @Override
6035            public Layout[] filterFindByG_P_P_PrevAndNext(long plid, long groupId,
6036                    boolean privateLayout, long parentLayoutId,
6037                    OrderByComparator<Layout> orderByComparator)
6038                    throws NoSuchLayoutException {
6039                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6040                            return findByG_P_P_PrevAndNext(plid, groupId, privateLayout,
6041                                    parentLayoutId, orderByComparator);
6042                    }
6043    
6044                    Layout layout = findByPrimaryKey(plid);
6045    
6046                    Session session = null;
6047    
6048                    try {
6049                            session = openSession();
6050    
6051                            Layout[] array = new LayoutImpl[3];
6052    
6053                            array[0] = filterGetByG_P_P_PrevAndNext(session, layout, groupId,
6054                                            privateLayout, parentLayoutId, orderByComparator, true);
6055    
6056                            array[1] = layout;
6057    
6058                            array[2] = filterGetByG_P_P_PrevAndNext(session, layout, groupId,
6059                                            privateLayout, parentLayoutId, orderByComparator, false);
6060    
6061                            return array;
6062                    }
6063                    catch (Exception e) {
6064                            throw processException(e);
6065                    }
6066                    finally {
6067                            closeSession(session);
6068                    }
6069            }
6070    
6071            protected Layout filterGetByG_P_P_PrevAndNext(Session session,
6072                    Layout layout, long groupId, boolean privateLayout,
6073                    long parentLayoutId, OrderByComparator<Layout> orderByComparator,
6074                    boolean previous) {
6075                    StringBundler query = null;
6076    
6077                    if (orderByComparator != null) {
6078                            query = new StringBundler(6 +
6079                                            (orderByComparator.getOrderByFields().length * 6));
6080                    }
6081                    else {
6082                            query = new StringBundler(3);
6083                    }
6084    
6085                    if (getDB().isSupportsInlineDistinct()) {
6086                            query.append(_FILTER_SQL_SELECT_LAYOUT_WHERE);
6087                    }
6088                    else {
6089                            query.append(_FILTER_SQL_SELECT_LAYOUT_NO_INLINE_DISTINCT_WHERE_1);
6090                    }
6091    
6092                    query.append(_FINDER_COLUMN_G_P_P_GROUPID_2);
6093    
6094                    query.append(_FINDER_COLUMN_G_P_P_PRIVATELAYOUT_2);
6095    
6096                    query.append(_FINDER_COLUMN_G_P_P_PARENTLAYOUTID_2);
6097    
6098                    if (!getDB().isSupportsInlineDistinct()) {
6099                            query.append(_FILTER_SQL_SELECT_LAYOUT_NO_INLINE_DISTINCT_WHERE_2);
6100                    }
6101    
6102                    if (orderByComparator != null) {
6103                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6104    
6105                            if (orderByConditionFields.length > 0) {
6106                                    query.append(WHERE_AND);
6107                            }
6108    
6109                            for (int i = 0; i < orderByConditionFields.length; i++) {
6110                                    if (getDB().isSupportsInlineDistinct()) {
6111                                            query.append(_ORDER_BY_ENTITY_ALIAS);
6112                                    }
6113                                    else {
6114                                            query.append(_ORDER_BY_ENTITY_TABLE);
6115                                    }
6116    
6117                                    query.append(orderByConditionFields[i]);
6118    
6119                                    if ((i + 1) < orderByConditionFields.length) {
6120                                            if (orderByComparator.isAscending() ^ previous) {
6121                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6122                                            }
6123                                            else {
6124                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6125                                            }
6126                                    }
6127                                    else {
6128                                            if (orderByComparator.isAscending() ^ previous) {
6129                                                    query.append(WHERE_GREATER_THAN);
6130                                            }
6131                                            else {
6132                                                    query.append(WHERE_LESSER_THAN);
6133                                            }
6134                                    }
6135                            }
6136    
6137                            query.append(ORDER_BY_CLAUSE);
6138    
6139                            String[] orderByFields = orderByComparator.getOrderByFields();
6140    
6141                            for (int i = 0; i < orderByFields.length; i++) {
6142                                    if (getDB().isSupportsInlineDistinct()) {
6143                                            query.append(_ORDER_BY_ENTITY_ALIAS);
6144                                    }
6145                                    else {
6146                                            query.append(_ORDER_BY_ENTITY_TABLE);
6147                                    }
6148    
6149                                    query.append(orderByFields[i]);
6150    
6151                                    if ((i + 1) < orderByFields.length) {
6152                                            if (orderByComparator.isAscending() ^ previous) {
6153                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6154                                            }
6155                                            else {
6156                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6157                                            }
6158                                    }
6159                                    else {
6160                                            if (orderByComparator.isAscending() ^ previous) {
6161                                                    query.append(ORDER_BY_ASC);
6162                                            }
6163                                            else {
6164                                                    query.append(ORDER_BY_DESC);
6165                                            }
6166                                    }
6167                            }
6168                    }
6169                    else {
6170                            if (getDB().isSupportsInlineDistinct()) {
6171                                    query.append(LayoutModelImpl.ORDER_BY_JPQL);
6172                            }
6173                            else {
6174                                    query.append(LayoutModelImpl.ORDER_BY_SQL);
6175                            }
6176                    }
6177    
6178                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6179                                    Layout.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN,
6180                                    groupId);
6181    
6182                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
6183    
6184                    q.setFirstResult(0);
6185                    q.setMaxResults(2);
6186    
6187                    if (getDB().isSupportsInlineDistinct()) {
6188                            q.addEntity(_FILTER_ENTITY_ALIAS, LayoutImpl.class);
6189                    }
6190                    else {
6191                            q.addEntity(_FILTER_ENTITY_TABLE, LayoutImpl.class);
6192                    }
6193    
6194                    QueryPos qPos = QueryPos.getInstance(q);
6195    
6196                    qPos.add(groupId);
6197    
6198                    qPos.add(privateLayout);
6199    
6200                    qPos.add(parentLayoutId);
6201    
6202                    if (orderByComparator != null) {
6203                            Object[] values = orderByComparator.getOrderByConditionValues(layout);
6204    
6205                            for (Object value : values) {
6206                                    qPos.add(value);
6207                            }
6208                    }
6209    
6210                    List<Layout> list = q.list();
6211    
6212                    if (list.size() == 2) {
6213                            return list.get(1);
6214                    }
6215                    else {
6216                            return null;
6217                    }
6218            }
6219    
6220            /**
6221             * Removes all the layouts where groupId = &#63; and privateLayout = &#63; and parentLayoutId = &#63; from the database.
6222             *
6223             * @param groupId the group ID
6224             * @param privateLayout the private layout
6225             * @param parentLayoutId the parent layout ID
6226             */
6227            @Override
6228            public void removeByG_P_P(long groupId, boolean privateLayout,
6229                    long parentLayoutId) {
6230                    for (Layout layout : findByG_P_P(groupId, privateLayout,
6231                                    parentLayoutId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
6232                            remove(layout);
6233                    }
6234            }
6235    
6236            /**
6237             * Returns the number of layouts where groupId = &#63; and privateLayout = &#63; and parentLayoutId = &#63;.
6238             *
6239             * @param groupId the group ID
6240             * @param privateLayout the private layout
6241             * @param parentLayoutId the parent layout ID
6242             * @return the number of matching layouts
6243             */
6244            @Override
6245            public int countByG_P_P(long groupId, boolean privateLayout,
6246                    long parentLayoutId) {
6247                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_P_P;
6248    
6249                    Object[] finderArgs = new Object[] {
6250                                    groupId, privateLayout, parentLayoutId
6251                            };
6252    
6253                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
6254    
6255                    if (count == null) {
6256                            StringBundler query = new StringBundler(4);
6257    
6258                            query.append(_SQL_COUNT_LAYOUT_WHERE);
6259    
6260                            query.append(_FINDER_COLUMN_G_P_P_GROUPID_2);
6261    
6262                            query.append(_FINDER_COLUMN_G_P_P_PRIVATELAYOUT_2);
6263    
6264                            query.append(_FINDER_COLUMN_G_P_P_PARENTLAYOUTID_2);
6265    
6266                            String sql = query.toString();
6267    
6268                            Session session = null;
6269    
6270                            try {
6271                                    session = openSession();
6272    
6273                                    Query q = session.createQuery(sql);
6274    
6275                                    QueryPos qPos = QueryPos.getInstance(q);
6276    
6277                                    qPos.add(groupId);
6278    
6279                                    qPos.add(privateLayout);
6280    
6281                                    qPos.add(parentLayoutId);
6282    
6283                                    count = (Long)q.uniqueResult();
6284    
6285                                    finderCache.putResult(finderPath, finderArgs, count);
6286                            }
6287                            catch (Exception e) {
6288                                    finderCache.removeResult(finderPath, finderArgs);
6289    
6290                                    throw processException(e);
6291                            }
6292                            finally {
6293                                    closeSession(session);
6294                            }
6295                    }
6296    
6297                    return count.intValue();
6298            }
6299    
6300            /**
6301             * Returns the number of layouts that the user has permission to view where groupId = &#63; and privateLayout = &#63; and parentLayoutId = &#63;.
6302             *
6303             * @param groupId the group ID
6304             * @param privateLayout the private layout
6305             * @param parentLayoutId the parent layout ID
6306             * @return the number of matching layouts that the user has permission to view
6307             */
6308            @Override
6309            public int filterCountByG_P_P(long groupId, boolean privateLayout,
6310                    long parentLayoutId) {
6311                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6312                            return countByG_P_P(groupId, privateLayout, parentLayoutId);
6313                    }
6314    
6315                    StringBundler query = new StringBundler(4);
6316    
6317                    query.append(_FILTER_SQL_COUNT_LAYOUT_WHERE);
6318    
6319                    query.append(_FINDER_COLUMN_G_P_P_GROUPID_2);
6320    
6321                    query.append(_FINDER_COLUMN_G_P_P_PRIVATELAYOUT_2);
6322    
6323                    query.append(_FINDER_COLUMN_G_P_P_PARENTLAYOUTID_2);
6324    
6325                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6326                                    Layout.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN,
6327                                    groupId);
6328    
6329                    Session session = null;
6330    
6331                    try {
6332                            session = openSession();
6333    
6334                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
6335    
6336                            q.addScalar(COUNT_COLUMN_NAME,
6337                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
6338    
6339                            QueryPos qPos = QueryPos.getInstance(q);
6340    
6341                            qPos.add(groupId);
6342    
6343                            qPos.add(privateLayout);
6344    
6345                            qPos.add(parentLayoutId);
6346    
6347                            Long count = (Long)q.uniqueResult();
6348    
6349                            return count.intValue();
6350                    }
6351                    catch (Exception e) {
6352                            throw processException(e);
6353                    }
6354                    finally {
6355                            closeSession(session);
6356                    }
6357            }
6358    
6359            private static final String _FINDER_COLUMN_G_P_P_GROUPID_2 = "layout.groupId = ? AND ";
6360            private static final String _FINDER_COLUMN_G_P_P_PRIVATELAYOUT_2 = "layout.privateLayout = ? AND ";
6361            private static final String _FINDER_COLUMN_G_P_P_PARENTLAYOUTID_2 = "layout.parentLayoutId = ?";
6362            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_T = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
6363                            LayoutModelImpl.FINDER_CACHE_ENABLED, LayoutImpl.class,
6364                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_P_T",
6365                            new String[] {
6366                                    Long.class.getName(), Boolean.class.getName(),
6367                                    String.class.getName(),
6368                                    
6369                            Integer.class.getName(), Integer.class.getName(),
6370                                    OrderByComparator.class.getName()
6371                            });
6372            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_T = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
6373                            LayoutModelImpl.FINDER_CACHE_ENABLED, LayoutImpl.class,
6374                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_P_T",
6375                            new String[] {
6376                                    Long.class.getName(), Boolean.class.getName(),
6377                                    String.class.getName()
6378                            },
6379                            LayoutModelImpl.GROUPID_COLUMN_BITMASK |
6380                            LayoutModelImpl.PRIVATELAYOUT_COLUMN_BITMASK |
6381                            LayoutModelImpl.TYPE_COLUMN_BITMASK |
6382                            LayoutModelImpl.PARENTLAYOUTID_COLUMN_BITMASK |
6383                            LayoutModelImpl.PRIORITY_COLUMN_BITMASK);
6384            public static final FinderPath FINDER_PATH_COUNT_BY_G_P_T = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
6385                            LayoutModelImpl.FINDER_CACHE_ENABLED, Long.class,
6386                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P_T",
6387                            new String[] {
6388                                    Long.class.getName(), Boolean.class.getName(),
6389                                    String.class.getName()
6390                            });
6391    
6392            /**
6393             * Returns all the layouts where groupId = &#63; and privateLayout = &#63; and type = &#63;.
6394             *
6395             * @param groupId the group ID
6396             * @param privateLayout the private layout
6397             * @param type the type
6398             * @return the matching layouts
6399             */
6400            @Override
6401            public List<Layout> findByG_P_T(long groupId, boolean privateLayout,
6402                    String type) {
6403                    return findByG_P_T(groupId, privateLayout, type, QueryUtil.ALL_POS,
6404                            QueryUtil.ALL_POS, null);
6405            }
6406    
6407            /**
6408             * Returns a range of all the layouts where groupId = &#63; and privateLayout = &#63; and type = &#63;.
6409             *
6410             * <p>
6411             * 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 LayoutModelImpl}. 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.
6412             * </p>
6413             *
6414             * @param groupId the group ID
6415             * @param privateLayout the private layout
6416             * @param type the type
6417             * @param start the lower bound of the range of layouts
6418             * @param end the upper bound of the range of layouts (not inclusive)
6419             * @return the range of matching layouts
6420             */
6421            @Override
6422            public List<Layout> findByG_P_T(long groupId, boolean privateLayout,
6423                    String type, int start, int end) {
6424                    return findByG_P_T(groupId, privateLayout, type, start, end, null);
6425            }
6426    
6427            /**
6428             * Returns an ordered range of all the layouts where groupId = &#63; and privateLayout = &#63; and type = &#63;.
6429             *
6430             * <p>
6431             * 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 LayoutModelImpl}. 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.
6432             * </p>
6433             *
6434             * @param groupId the group ID
6435             * @param privateLayout the private layout
6436             * @param type the type
6437             * @param start the lower bound of the range of layouts
6438             * @param end the upper bound of the range of layouts (not inclusive)
6439             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6440             * @return the ordered range of matching layouts
6441             */
6442            @Override
6443            public List<Layout> findByG_P_T(long groupId, boolean privateLayout,
6444                    String type, int start, int end,
6445                    OrderByComparator<Layout> orderByComparator) {
6446                    return findByG_P_T(groupId, privateLayout, type, start, end,
6447                            orderByComparator, true);
6448            }
6449    
6450            /**
6451             * Returns an ordered range of all the layouts where groupId = &#63; and privateLayout = &#63; and type = &#63;.
6452             *
6453             * <p>
6454             * 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 LayoutModelImpl}. 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.
6455             * </p>
6456             *
6457             * @param groupId the group ID
6458             * @param privateLayout the private layout
6459             * @param type the type
6460             * @param start the lower bound of the range of layouts
6461             * @param end the upper bound of the range of layouts (not inclusive)
6462             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6463             * @param retrieveFromCache whether to retrieve from the finder cache
6464             * @return the ordered range of matching layouts
6465             */
6466            @Override
6467            public List<Layout> findByG_P_T(long groupId, boolean privateLayout,
6468                    String type, int start, int end,
6469                    OrderByComparator<Layout> orderByComparator, boolean retrieveFromCache) {
6470                    boolean pagination = true;
6471                    FinderPath finderPath = null;
6472                    Object[] finderArgs = null;
6473    
6474                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6475                                    (orderByComparator == null)) {
6476                            pagination = false;
6477                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_T;
6478                            finderArgs = new Object[] { groupId, privateLayout, type };
6479                    }
6480                    else {
6481                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_T;
6482                            finderArgs = new Object[] {
6483                                            groupId, privateLayout, type,
6484                                            
6485                                            start, end, orderByComparator
6486                                    };
6487                    }
6488    
6489                    List<Layout> list = null;
6490    
6491                    if (retrieveFromCache) {
6492                            list = (List<Layout>)finderCache.getResult(finderPath, finderArgs,
6493                                            this);
6494    
6495                            if ((list != null) && !list.isEmpty()) {
6496                                    for (Layout layout : list) {
6497                                            if ((groupId != layout.getGroupId()) ||
6498                                                            (privateLayout != layout.getPrivateLayout()) ||
6499                                                            !Validator.equals(type, layout.getType())) {
6500                                                    list = null;
6501    
6502                                                    break;
6503                                            }
6504                                    }
6505                            }
6506                    }
6507    
6508                    if (list == null) {
6509                            StringBundler query = null;
6510    
6511                            if (orderByComparator != null) {
6512                                    query = new StringBundler(5 +
6513                                                    (orderByComparator.getOrderByFields().length * 3));
6514                            }
6515                            else {
6516                                    query = new StringBundler(5);
6517                            }
6518    
6519                            query.append(_SQL_SELECT_LAYOUT_WHERE);
6520    
6521                            query.append(_FINDER_COLUMN_G_P_T_GROUPID_2);
6522    
6523                            query.append(_FINDER_COLUMN_G_P_T_PRIVATELAYOUT_2);
6524    
6525                            boolean bindType = false;
6526    
6527                            if (type == null) {
6528                                    query.append(_FINDER_COLUMN_G_P_T_TYPE_1);
6529                            }
6530                            else if (type.equals(StringPool.BLANK)) {
6531                                    query.append(_FINDER_COLUMN_G_P_T_TYPE_3);
6532                            }
6533                            else {
6534                                    bindType = true;
6535    
6536                                    query.append(_FINDER_COLUMN_G_P_T_TYPE_2);
6537                            }
6538    
6539                            if (orderByComparator != null) {
6540                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6541                                            orderByComparator);
6542                            }
6543                            else
6544                             if (pagination) {
6545                                    query.append(LayoutModelImpl.ORDER_BY_JPQL);
6546                            }
6547    
6548                            String sql = query.toString();
6549    
6550                            Session session = null;
6551    
6552                            try {
6553                                    session = openSession();
6554    
6555                                    Query q = session.createQuery(sql);
6556    
6557                                    QueryPos qPos = QueryPos.getInstance(q);
6558    
6559                                    qPos.add(groupId);
6560    
6561                                    qPos.add(privateLayout);
6562    
6563                                    if (bindType) {
6564                                            qPos.add(type);
6565                                    }
6566    
6567                                    if (!pagination) {
6568                                            list = (List<Layout>)QueryUtil.list(q, getDialect(), start,
6569                                                            end, false);
6570    
6571                                            Collections.sort(list);
6572    
6573                                            list = Collections.unmodifiableList(list);
6574                                    }
6575                                    else {
6576                                            list = (List<Layout>)QueryUtil.list(q, getDialect(), start,
6577                                                            end);
6578                                    }
6579    
6580                                    cacheResult(list);
6581    
6582                                    finderCache.putResult(finderPath, finderArgs, list);
6583                            }
6584                            catch (Exception e) {
6585                                    finderCache.removeResult(finderPath, finderArgs);
6586    
6587                                    throw processException(e);
6588                            }
6589                            finally {
6590                                    closeSession(session);
6591                            }
6592                    }
6593    
6594                    return list;
6595            }
6596    
6597            /**
6598             * Returns the first layout in the ordered set where groupId = &#63; and privateLayout = &#63; and type = &#63;.
6599             *
6600             * @param groupId the group ID
6601             * @param privateLayout the private layout
6602             * @param type the type
6603             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6604             * @return the first matching layout
6605             * @throws NoSuchLayoutException if a matching layout could not be found
6606             */
6607            @Override
6608            public Layout findByG_P_T_First(long groupId, boolean privateLayout,
6609                    String type, OrderByComparator<Layout> orderByComparator)
6610                    throws NoSuchLayoutException {
6611                    Layout layout = fetchByG_P_T_First(groupId, privateLayout, type,
6612                                    orderByComparator);
6613    
6614                    if (layout != null) {
6615                            return layout;
6616                    }
6617    
6618                    StringBundler msg = new StringBundler(8);
6619    
6620                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6621    
6622                    msg.append("groupId=");
6623                    msg.append(groupId);
6624    
6625                    msg.append(", privateLayout=");
6626                    msg.append(privateLayout);
6627    
6628                    msg.append(", type=");
6629                    msg.append(type);
6630    
6631                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6632    
6633                    throw new NoSuchLayoutException(msg.toString());
6634            }
6635    
6636            /**
6637             * Returns the first layout in the ordered set where groupId = &#63; and privateLayout = &#63; and type = &#63;.
6638             *
6639             * @param groupId the group ID
6640             * @param privateLayout the private layout
6641             * @param type the type
6642             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6643             * @return the first matching layout, or <code>null</code> if a matching layout could not be found
6644             */
6645            @Override
6646            public Layout fetchByG_P_T_First(long groupId, boolean privateLayout,
6647                    String type, OrderByComparator<Layout> orderByComparator) {
6648                    List<Layout> list = findByG_P_T(groupId, privateLayout, type, 0, 1,
6649                                    orderByComparator);
6650    
6651                    if (!list.isEmpty()) {
6652                            return list.get(0);
6653                    }
6654    
6655                    return null;
6656            }
6657    
6658            /**
6659             * Returns the last layout in the ordered set where groupId = &#63; and privateLayout = &#63; and type = &#63;.
6660             *
6661             * @param groupId the group ID
6662             * @param privateLayout the private layout
6663             * @param type the type
6664             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6665             * @return the last matching layout
6666             * @throws NoSuchLayoutException if a matching layout could not be found
6667             */
6668            @Override
6669            public Layout findByG_P_T_Last(long groupId, boolean privateLayout,
6670                    String type, OrderByComparator<Layout> orderByComparator)
6671                    throws NoSuchLayoutException {
6672                    Layout layout = fetchByG_P_T_Last(groupId, privateLayout, type,
6673                                    orderByComparator);
6674    
6675                    if (layout != null) {
6676                            return layout;
6677                    }
6678    
6679                    StringBundler msg = new StringBundler(8);
6680    
6681                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6682    
6683                    msg.append("groupId=");
6684                    msg.append(groupId);
6685    
6686                    msg.append(", privateLayout=");
6687                    msg.append(privateLayout);
6688    
6689                    msg.append(", type=");
6690                    msg.append(type);
6691    
6692                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6693    
6694                    throw new NoSuchLayoutException(msg.toString());
6695            }
6696    
6697            /**
6698             * Returns the last layout in the ordered set where groupId = &#63; and privateLayout = &#63; and type = &#63;.
6699             *
6700             * @param groupId the group ID
6701             * @param privateLayout the private layout
6702             * @param type the type
6703             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6704             * @return the last matching layout, or <code>null</code> if a matching layout could not be found
6705             */
6706            @Override
6707            public Layout fetchByG_P_T_Last(long groupId, boolean privateLayout,
6708                    String type, OrderByComparator<Layout> orderByComparator) {
6709                    int count = countByG_P_T(groupId, privateLayout, type);
6710    
6711                    if (count == 0) {
6712                            return null;
6713                    }
6714    
6715                    List<Layout> list = findByG_P_T(groupId, privateLayout, type,
6716                                    count - 1, count, orderByComparator);
6717    
6718                    if (!list.isEmpty()) {
6719                            return list.get(0);
6720                    }
6721    
6722                    return null;
6723            }
6724    
6725            /**
6726             * Returns the layouts before and after the current layout in the ordered set where groupId = &#63; and privateLayout = &#63; and type = &#63;.
6727             *
6728             * @param plid the primary key of the current layout
6729             * @param groupId the group ID
6730             * @param privateLayout the private layout
6731             * @param type the type
6732             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6733             * @return the previous, current, and next layout
6734             * @throws NoSuchLayoutException if a layout with the primary key could not be found
6735             */
6736            @Override
6737            public Layout[] findByG_P_T_PrevAndNext(long plid, long groupId,
6738                    boolean privateLayout, String type,
6739                    OrderByComparator<Layout> orderByComparator)
6740                    throws NoSuchLayoutException {
6741                    Layout layout = findByPrimaryKey(plid);
6742    
6743                    Session session = null;
6744    
6745                    try {
6746                            session = openSession();
6747    
6748                            Layout[] array = new LayoutImpl[3];
6749    
6750                            array[0] = getByG_P_T_PrevAndNext(session, layout, groupId,
6751                                            privateLayout, type, orderByComparator, true);
6752    
6753                            array[1] = layout;
6754    
6755                            array[2] = getByG_P_T_PrevAndNext(session, layout, groupId,
6756                                            privateLayout, type, orderByComparator, false);
6757    
6758                            return array;
6759                    }
6760                    catch (Exception e) {
6761                            throw processException(e);
6762                    }
6763                    finally {
6764                            closeSession(session);
6765                    }
6766            }
6767    
6768            protected Layout getByG_P_T_PrevAndNext(Session session, Layout layout,
6769                    long groupId, boolean privateLayout, String type,
6770                    OrderByComparator<Layout> orderByComparator, boolean previous) {
6771                    StringBundler query = null;
6772    
6773                    if (orderByComparator != null) {
6774                            query = new StringBundler(6 +
6775                                            (orderByComparator.getOrderByFields().length * 6));
6776                    }
6777                    else {
6778                            query = new StringBundler(3);
6779                    }
6780    
6781                    query.append(_SQL_SELECT_LAYOUT_WHERE);
6782    
6783                    query.append(_FINDER_COLUMN_G_P_T_GROUPID_2);
6784    
6785                    query.append(_FINDER_COLUMN_G_P_T_PRIVATELAYOUT_2);
6786    
6787                    boolean bindType = false;
6788    
6789                    if (type == null) {
6790                            query.append(_FINDER_COLUMN_G_P_T_TYPE_1);
6791                    }
6792                    else if (type.equals(StringPool.BLANK)) {
6793                            query.append(_FINDER_COLUMN_G_P_T_TYPE_3);
6794                    }
6795                    else {
6796                            bindType = true;
6797    
6798                            query.append(_FINDER_COLUMN_G_P_T_TYPE_2);
6799                    }
6800    
6801                    if (orderByComparator != null) {
6802                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6803    
6804                            if (orderByConditionFields.length > 0) {
6805                                    query.append(WHERE_AND);
6806                            }
6807    
6808                            for (int i = 0; i < orderByConditionFields.length; i++) {
6809                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6810                                    query.append(orderByConditionFields[i]);
6811    
6812                                    if ((i + 1) < orderByConditionFields.length) {
6813                                            if (orderByComparator.isAscending() ^ previous) {
6814                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6815                                            }
6816                                            else {
6817                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6818                                            }
6819                                    }
6820                                    else {
6821                                            if (orderByComparator.isAscending() ^ previous) {
6822                                                    query.append(WHERE_GREATER_THAN);
6823                                            }
6824                                            else {
6825                                                    query.append(WHERE_LESSER_THAN);
6826                                            }
6827                                    }
6828                            }
6829    
6830                            query.append(ORDER_BY_CLAUSE);
6831    
6832                            String[] orderByFields = orderByComparator.getOrderByFields();
6833    
6834                            for (int i = 0; i < orderByFields.length; i++) {
6835                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6836                                    query.append(orderByFields[i]);
6837    
6838                                    if ((i + 1) < orderByFields.length) {
6839                                            if (orderByComparator.isAscending() ^ previous) {
6840                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6841                                            }
6842                                            else {
6843                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6844                                            }
6845                                    }
6846                                    else {
6847                                            if (orderByComparator.isAscending() ^ previous) {
6848                                                    query.append(ORDER_BY_ASC);
6849                                            }
6850                                            else {
6851                                                    query.append(ORDER_BY_DESC);
6852                                            }
6853                                    }
6854                            }
6855                    }
6856                    else {
6857                            query.append(LayoutModelImpl.ORDER_BY_JPQL);
6858                    }
6859    
6860                    String sql = query.toString();
6861    
6862                    Query q = session.createQuery(sql);
6863    
6864                    q.setFirstResult(0);
6865                    q.setMaxResults(2);
6866    
6867                    QueryPos qPos = QueryPos.getInstance(q);
6868    
6869                    qPos.add(groupId);
6870    
6871                    qPos.add(privateLayout);
6872    
6873                    if (bindType) {
6874                            qPos.add(type);
6875                    }
6876    
6877                    if (orderByComparator != null) {
6878                            Object[] values = orderByComparator.getOrderByConditionValues(layout);
6879    
6880                            for (Object value : values) {
6881                                    qPos.add(value);
6882                            }
6883                    }
6884    
6885                    List<Layout> list = q.list();
6886    
6887                    if (list.size() == 2) {
6888                            return list.get(1);
6889                    }
6890                    else {
6891                            return null;
6892                    }
6893            }
6894    
6895            /**
6896             * Returns all the layouts that the user has permission to view where groupId = &#63; and privateLayout = &#63; and type = &#63;.
6897             *
6898             * @param groupId the group ID
6899             * @param privateLayout the private layout
6900             * @param type the type
6901             * @return the matching layouts that the user has permission to view
6902             */
6903            @Override
6904            public List<Layout> filterFindByG_P_T(long groupId, boolean privateLayout,
6905                    String type) {
6906                    return filterFindByG_P_T(groupId, privateLayout, type,
6907                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
6908            }
6909    
6910            /**
6911             * Returns a range of all the layouts that the user has permission to view where groupId = &#63; and privateLayout = &#63; and type = &#63;.
6912             *
6913             * <p>
6914             * 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 LayoutModelImpl}. 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.
6915             * </p>
6916             *
6917             * @param groupId the group ID
6918             * @param privateLayout the private layout
6919             * @param type the type
6920             * @param start the lower bound of the range of layouts
6921             * @param end the upper bound of the range of layouts (not inclusive)
6922             * @return the range of matching layouts that the user has permission to view
6923             */
6924            @Override
6925            public List<Layout> filterFindByG_P_T(long groupId, boolean privateLayout,
6926                    String type, int start, int end) {
6927                    return filterFindByG_P_T(groupId, privateLayout, type, start, end, null);
6928            }
6929    
6930            /**
6931             * Returns an ordered range of all the layouts that the user has permissions to view where groupId = &#63; and privateLayout = &#63; and type = &#63;.
6932             *
6933             * <p>
6934             * 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 LayoutModelImpl}. 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.
6935             * </p>
6936             *
6937             * @param groupId the group ID
6938             * @param privateLayout the private layout
6939             * @param type the type
6940             * @param start the lower bound of the range of layouts
6941             * @param end the upper bound of the range of layouts (not inclusive)
6942             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6943             * @return the ordered range of matching layouts that the user has permission to view
6944             */
6945            @Override
6946            public List<Layout> filterFindByG_P_T(long groupId, boolean privateLayout,
6947                    String type, int start, int end,
6948                    OrderByComparator<Layout> orderByComparator) {
6949                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6950                            return findByG_P_T(groupId, privateLayout, type, start, end,
6951                                    orderByComparator);
6952                    }
6953    
6954                    StringBundler query = null;
6955    
6956                    if (orderByComparator != null) {
6957                            query = new StringBundler(5 +
6958                                            (orderByComparator.getOrderByFields().length * 3));
6959                    }
6960                    else {
6961                            query = new StringBundler(5);
6962                    }
6963    
6964                    if (getDB().isSupportsInlineDistinct()) {
6965                            query.append(_FILTER_SQL_SELECT_LAYOUT_WHERE);
6966                    }
6967                    else {
6968                            query.append(_FILTER_SQL_SELECT_LAYOUT_NO_INLINE_DISTINCT_WHERE_1);
6969                    }
6970    
6971                    query.append(_FINDER_COLUMN_G_P_T_GROUPID_2);
6972    
6973                    query.append(_FINDER_COLUMN_G_P_T_PRIVATELAYOUT_2);
6974    
6975                    boolean bindType = false;
6976    
6977                    if (type == null) {
6978                            query.append(_FINDER_COLUMN_G_P_T_TYPE_1_SQL);
6979                    }
6980                    else if (type.equals(StringPool.BLANK)) {
6981                            query.append(_FINDER_COLUMN_G_P_T_TYPE_3_SQL);
6982                    }
6983                    else {
6984                            bindType = true;
6985    
6986                            query.append(_FINDER_COLUMN_G_P_T_TYPE_2_SQL);
6987                    }
6988    
6989                    if (!getDB().isSupportsInlineDistinct()) {
6990                            query.append(_FILTER_SQL_SELECT_LAYOUT_NO_INLINE_DISTINCT_WHERE_2);
6991                    }
6992    
6993                    if (orderByComparator != null) {
6994                            if (getDB().isSupportsInlineDistinct()) {
6995                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6996                                            orderByComparator, true);
6997                            }
6998                            else {
6999                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
7000                                            orderByComparator, true);
7001                            }
7002                    }
7003                    else {
7004                            if (getDB().isSupportsInlineDistinct()) {
7005                                    query.append(LayoutModelImpl.ORDER_BY_JPQL);
7006                            }
7007                            else {
7008                                    query.append(LayoutModelImpl.ORDER_BY_SQL);
7009                            }
7010                    }
7011    
7012                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7013                                    Layout.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN,
7014                                    groupId);
7015    
7016                    Session session = null;
7017    
7018                    try {
7019                            session = openSession();
7020    
7021                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
7022    
7023                            if (getDB().isSupportsInlineDistinct()) {
7024                                    q.addEntity(_FILTER_ENTITY_ALIAS, LayoutImpl.class);
7025                            }
7026                            else {
7027                                    q.addEntity(_FILTER_ENTITY_TABLE, LayoutImpl.class);
7028                            }
7029    
7030                            QueryPos qPos = QueryPos.getInstance(q);
7031    
7032                            qPos.add(groupId);
7033    
7034                            qPos.add(privateLayout);
7035    
7036                            if (bindType) {
7037                                    qPos.add(type);
7038                            }
7039    
7040                            return (List<Layout>)QueryUtil.list(q, getDialect(), start, end);
7041                    }
7042                    catch (Exception e) {
7043                            throw processException(e);
7044                    }
7045                    finally {
7046                            closeSession(session);
7047                    }
7048            }
7049    
7050            /**
7051             * Returns the layouts before and after the current layout in the ordered set of layouts that the user has permission to view where groupId = &#63; and privateLayout = &#63; and type = &#63;.
7052             *
7053             * @param plid the primary key of the current layout
7054             * @param groupId the group ID
7055             * @param privateLayout the private layout
7056             * @param type the type
7057             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7058             * @return the previous, current, and next layout
7059             * @throws NoSuchLayoutException if a layout with the primary key could not be found
7060             */
7061            @Override
7062            public Layout[] filterFindByG_P_T_PrevAndNext(long plid, long groupId,
7063                    boolean privateLayout, String type,
7064                    OrderByComparator<Layout> orderByComparator)
7065                    throws NoSuchLayoutException {
7066                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7067                            return findByG_P_T_PrevAndNext(plid, groupId, privateLayout, type,
7068                                    orderByComparator);
7069                    }
7070    
7071                    Layout layout = findByPrimaryKey(plid);
7072    
7073                    Session session = null;
7074    
7075                    try {
7076                            session = openSession();
7077    
7078                            Layout[] array = new LayoutImpl[3];
7079    
7080                            array[0] = filterGetByG_P_T_PrevAndNext(session, layout, groupId,
7081                                            privateLayout, type, orderByComparator, true);
7082    
7083                            array[1] = layout;
7084    
7085                            array[2] = filterGetByG_P_T_PrevAndNext(session, layout, groupId,
7086                                            privateLayout, type, orderByComparator, false);
7087    
7088                            return array;
7089                    }
7090                    catch (Exception e) {
7091                            throw processException(e);
7092                    }
7093                    finally {
7094                            closeSession(session);
7095                    }
7096            }
7097    
7098            protected Layout filterGetByG_P_T_PrevAndNext(Session session,
7099                    Layout layout, long groupId, boolean privateLayout, String type,
7100                    OrderByComparator<Layout> orderByComparator, boolean previous) {
7101                    StringBundler query = null;
7102    
7103                    if (orderByComparator != null) {
7104                            query = new StringBundler(6 +
7105                                            (orderByComparator.getOrderByFields().length * 6));
7106                    }
7107                    else {
7108                            query = new StringBundler(3);
7109                    }
7110    
7111                    if (getDB().isSupportsInlineDistinct()) {
7112                            query.append(_FILTER_SQL_SELECT_LAYOUT_WHERE);
7113                    }
7114                    else {
7115                            query.append(_FILTER_SQL_SELECT_LAYOUT_NO_INLINE_DISTINCT_WHERE_1);
7116                    }
7117    
7118                    query.append(_FINDER_COLUMN_G_P_T_GROUPID_2);
7119    
7120                    query.append(_FINDER_COLUMN_G_P_T_PRIVATELAYOUT_2);
7121    
7122                    boolean bindType = false;
7123    
7124                    if (type == null) {
7125                            query.append(_FINDER_COLUMN_G_P_T_TYPE_1_SQL);
7126                    }
7127                    else if (type.equals(StringPool.BLANK)) {
7128                            query.append(_FINDER_COLUMN_G_P_T_TYPE_3_SQL);
7129                    }
7130                    else {
7131                            bindType = true;
7132    
7133                            query.append(_FINDER_COLUMN_G_P_T_TYPE_2_SQL);
7134                    }
7135    
7136                    if (!getDB().isSupportsInlineDistinct()) {
7137                            query.append(_FILTER_SQL_SELECT_LAYOUT_NO_INLINE_DISTINCT_WHERE_2);
7138                    }
7139    
7140                    if (orderByComparator != null) {
7141                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7142    
7143                            if (orderByConditionFields.length > 0) {
7144                                    query.append(WHERE_AND);
7145                            }
7146    
7147                            for (int i = 0; i < orderByConditionFields.length; i++) {
7148                                    if (getDB().isSupportsInlineDistinct()) {
7149                                            query.append(_ORDER_BY_ENTITY_ALIAS);
7150                                    }
7151                                    else {
7152                                            query.append(_ORDER_BY_ENTITY_TABLE);
7153                                    }
7154    
7155                                    query.append(orderByConditionFields[i]);
7156    
7157                                    if ((i + 1) < orderByConditionFields.length) {
7158                                            if (orderByComparator.isAscending() ^ previous) {
7159                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
7160                                            }
7161                                            else {
7162                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
7163                                            }
7164                                    }
7165                                    else {
7166                                            if (orderByComparator.isAscending() ^ previous) {
7167                                                    query.append(WHERE_GREATER_THAN);
7168                                            }
7169                                            else {
7170                                                    query.append(WHERE_LESSER_THAN);
7171                                            }
7172                                    }
7173                            }
7174    
7175                            query.append(ORDER_BY_CLAUSE);
7176    
7177                            String[] orderByFields = orderByComparator.getOrderByFields();
7178    
7179                            for (int i = 0; i < orderByFields.length; i++) {
7180                                    if (getDB().isSupportsInlineDistinct()) {
7181                                            query.append(_ORDER_BY_ENTITY_ALIAS);
7182                                    }
7183                                    else {
7184                                            query.append(_ORDER_BY_ENTITY_TABLE);
7185                                    }
7186    
7187                                    query.append(orderByFields[i]);
7188    
7189                                    if ((i + 1) < orderByFields.length) {
7190                                            if (orderByComparator.isAscending() ^ previous) {
7191                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
7192                                            }
7193                                            else {
7194                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
7195                                            }
7196                                    }
7197                                    else {
7198                                            if (orderByComparator.isAscending() ^ previous) {
7199                                                    query.append(ORDER_BY_ASC);
7200                                            }
7201                                            else {
7202                                                    query.append(ORDER_BY_DESC);
7203                                            }
7204                                    }
7205                            }
7206                    }
7207                    else {
7208                            if (getDB().isSupportsInlineDistinct()) {
7209                                    query.append(LayoutModelImpl.ORDER_BY_JPQL);
7210                            }
7211                            else {
7212                                    query.append(LayoutModelImpl.ORDER_BY_SQL);
7213                            }
7214                    }
7215    
7216                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7217                                    Layout.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN,
7218                                    groupId);
7219    
7220                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
7221    
7222                    q.setFirstResult(0);
7223                    q.setMaxResults(2);
7224    
7225                    if (getDB().isSupportsInlineDistinct()) {
7226                            q.addEntity(_FILTER_ENTITY_ALIAS, LayoutImpl.class);
7227                    }
7228                    else {
7229                            q.addEntity(_FILTER_ENTITY_TABLE, LayoutImpl.class);
7230                    }
7231    
7232                    QueryPos qPos = QueryPos.getInstance(q);
7233    
7234                    qPos.add(groupId);
7235    
7236                    qPos.add(privateLayout);
7237    
7238                    if (bindType) {
7239                            qPos.add(type);
7240                    }
7241    
7242                    if (orderByComparator != null) {
7243                            Object[] values = orderByComparator.getOrderByConditionValues(layout);
7244    
7245                            for (Object value : values) {
7246                                    qPos.add(value);
7247                            }
7248                    }
7249    
7250                    List<Layout> list = q.list();
7251    
7252                    if (list.size() == 2) {
7253                            return list.get(1);
7254                    }
7255                    else {
7256                            return null;
7257                    }
7258            }
7259    
7260            /**
7261             * Removes all the layouts where groupId = &#63; and privateLayout = &#63; and type = &#63; from the database.
7262             *
7263             * @param groupId the group ID
7264             * @param privateLayout the private layout
7265             * @param type the type
7266             */
7267            @Override
7268            public void removeByG_P_T(long groupId, boolean privateLayout, String type) {
7269                    for (Layout layout : findByG_P_T(groupId, privateLayout, type,
7270                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
7271                            remove(layout);
7272                    }
7273            }
7274    
7275            /**
7276             * Returns the number of layouts where groupId = &#63; and privateLayout = &#63; and type = &#63;.
7277             *
7278             * @param groupId the group ID
7279             * @param privateLayout the private layout
7280             * @param type the type
7281             * @return the number of matching layouts
7282             */
7283            @Override
7284            public int countByG_P_T(long groupId, boolean privateLayout, String type) {
7285                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_P_T;
7286    
7287                    Object[] finderArgs = new Object[] { groupId, privateLayout, type };
7288    
7289                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
7290    
7291                    if (count == null) {
7292                            StringBundler query = new StringBundler(4);
7293    
7294                            query.append(_SQL_COUNT_LAYOUT_WHERE);
7295    
7296                            query.append(_FINDER_COLUMN_G_P_T_GROUPID_2);
7297    
7298                            query.append(_FINDER_COLUMN_G_P_T_PRIVATELAYOUT_2);
7299    
7300                            boolean bindType = false;
7301    
7302                            if (type == null) {
7303                                    query.append(_FINDER_COLUMN_G_P_T_TYPE_1);
7304                            }
7305                            else if (type.equals(StringPool.BLANK)) {
7306                                    query.append(_FINDER_COLUMN_G_P_T_TYPE_3);
7307                            }
7308                            else {
7309                                    bindType = true;
7310    
7311                                    query.append(_FINDER_COLUMN_G_P_T_TYPE_2);
7312                            }
7313    
7314                            String sql = query.toString();
7315    
7316                            Session session = null;
7317    
7318                            try {
7319                                    session = openSession();
7320    
7321                                    Query q = session.createQuery(sql);
7322    
7323                                    QueryPos qPos = QueryPos.getInstance(q);
7324    
7325                                    qPos.add(groupId);
7326    
7327                                    qPos.add(privateLayout);
7328    
7329                                    if (bindType) {
7330                                            qPos.add(type);
7331                                    }
7332    
7333                                    count = (Long)q.uniqueResult();
7334    
7335                                    finderCache.putResult(finderPath, finderArgs, count);
7336                            }
7337                            catch (Exception e) {
7338                                    finderCache.removeResult(finderPath, finderArgs);
7339    
7340                                    throw processException(e);
7341                            }
7342                            finally {
7343                                    closeSession(session);
7344                            }
7345                    }
7346    
7347                    return count.intValue();
7348            }
7349    
7350            /**
7351             * Returns the number of layouts that the user has permission to view where groupId = &#63; and privateLayout = &#63; and type = &#63;.
7352             *
7353             * @param groupId the group ID
7354             * @param privateLayout the private layout
7355             * @param type the type
7356             * @return the number of matching layouts that the user has permission to view
7357             */
7358            @Override
7359            public int filterCountByG_P_T(long groupId, boolean privateLayout,
7360                    String type) {
7361                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7362                            return countByG_P_T(groupId, privateLayout, type);
7363                    }
7364    
7365                    StringBundler query = new StringBundler(4);
7366    
7367                    query.append(_FILTER_SQL_COUNT_LAYOUT_WHERE);
7368    
7369                    query.append(_FINDER_COLUMN_G_P_T_GROUPID_2);
7370    
7371                    query.append(_FINDER_COLUMN_G_P_T_PRIVATELAYOUT_2);
7372    
7373                    boolean bindType = false;
7374    
7375                    if (type == null) {
7376                            query.append(_FINDER_COLUMN_G_P_T_TYPE_1_SQL);
7377                    }
7378                    else if (type.equals(StringPool.BLANK)) {
7379                            query.append(_FINDER_COLUMN_G_P_T_TYPE_3_SQL);
7380                    }
7381                    else {
7382                            bindType = true;
7383    
7384                            query.append(_FINDER_COLUMN_G_P_T_TYPE_2_SQL);
7385                    }
7386    
7387                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7388                                    Layout.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN,
7389                                    groupId);
7390    
7391                    Session session = null;
7392    
7393                    try {
7394                            session = openSession();
7395    
7396                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
7397    
7398                            q.addScalar(COUNT_COLUMN_NAME,
7399                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
7400    
7401                            QueryPos qPos = QueryPos.getInstance(q);
7402    
7403                            qPos.add(groupId);
7404    
7405                            qPos.add(privateLayout);
7406    
7407                            if (bindType) {
7408                                    qPos.add(type);
7409                            }
7410    
7411                            Long count = (Long)q.uniqueResult();
7412    
7413                            return count.intValue();
7414                    }
7415                    catch (Exception e) {
7416                            throw processException(e);
7417                    }
7418                    finally {
7419                            closeSession(session);
7420                    }
7421            }
7422    
7423            private static final String _FINDER_COLUMN_G_P_T_GROUPID_2 = "layout.groupId = ? AND ";
7424            private static final String _FINDER_COLUMN_G_P_T_PRIVATELAYOUT_2 = "layout.privateLayout = ? AND ";
7425            private static final String _FINDER_COLUMN_G_P_T_TYPE_1 = "layout.type IS NULL";
7426            private static final String _FINDER_COLUMN_G_P_T_TYPE_2 = "layout.type = ?";
7427            private static final String _FINDER_COLUMN_G_P_T_TYPE_3 = "(layout.type IS NULL OR layout.type = '')";
7428            private static final String _FINDER_COLUMN_G_P_T_TYPE_1_SQL = "layout.type_ IS NULL";
7429            private static final String _FINDER_COLUMN_G_P_T_TYPE_2_SQL = "layout.type_ = ?";
7430            private static final String _FINDER_COLUMN_G_P_T_TYPE_3_SQL = "(layout.type_ IS NULL OR layout.type_ = '')";
7431            public static final FinderPath FINDER_PATH_FETCH_BY_G_P_F = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
7432                            LayoutModelImpl.FINDER_CACHE_ENABLED, LayoutImpl.class,
7433                            FINDER_CLASS_NAME_ENTITY, "fetchByG_P_F",
7434                            new String[] {
7435                                    Long.class.getName(), Boolean.class.getName(),
7436                                    String.class.getName()
7437                            },
7438                            LayoutModelImpl.GROUPID_COLUMN_BITMASK |
7439                            LayoutModelImpl.PRIVATELAYOUT_COLUMN_BITMASK |
7440                            LayoutModelImpl.FRIENDLYURL_COLUMN_BITMASK);
7441            public static final FinderPath FINDER_PATH_COUNT_BY_G_P_F = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
7442                            LayoutModelImpl.FINDER_CACHE_ENABLED, Long.class,
7443                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P_F",
7444                            new String[] {
7445                                    Long.class.getName(), Boolean.class.getName(),
7446                                    String.class.getName()
7447                            });
7448    
7449            /**
7450             * Returns the layout where groupId = &#63; and privateLayout = &#63; and friendlyURL = &#63; or throws a {@link NoSuchLayoutException} if it could not be found.
7451             *
7452             * @param groupId the group ID
7453             * @param privateLayout the private layout
7454             * @param friendlyURL the friendly u r l
7455             * @return the matching layout
7456             * @throws NoSuchLayoutException if a matching layout could not be found
7457             */
7458            @Override
7459            public Layout findByG_P_F(long groupId, boolean privateLayout,
7460                    String friendlyURL) throws NoSuchLayoutException {
7461                    Layout layout = fetchByG_P_F(groupId, privateLayout, friendlyURL);
7462    
7463                    if (layout == null) {
7464                            StringBundler msg = new StringBundler(8);
7465    
7466                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7467    
7468                            msg.append("groupId=");
7469                            msg.append(groupId);
7470    
7471                            msg.append(", privateLayout=");
7472                            msg.append(privateLayout);
7473    
7474                            msg.append(", friendlyURL=");
7475                            msg.append(friendlyURL);
7476    
7477                            msg.append(StringPool.CLOSE_CURLY_BRACE);
7478    
7479                            if (_log.isWarnEnabled()) {
7480                                    _log.warn(msg.toString());
7481                            }
7482    
7483                            throw new NoSuchLayoutException(msg.toString());
7484                    }
7485    
7486                    return layout;
7487            }
7488    
7489            /**
7490             * Returns the layout where groupId = &#63; and privateLayout = &#63; and friendlyURL = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
7491             *
7492             * @param groupId the group ID
7493             * @param privateLayout the private layout
7494             * @param friendlyURL the friendly u r l
7495             * @return the matching layout, or <code>null</code> if a matching layout could not be found
7496             */
7497            @Override
7498            public Layout fetchByG_P_F(long groupId, boolean privateLayout,
7499                    String friendlyURL) {
7500                    return fetchByG_P_F(groupId, privateLayout, friendlyURL, true);
7501            }
7502    
7503            /**
7504             * Returns the layout where groupId = &#63; and privateLayout = &#63; and friendlyURL = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
7505             *
7506             * @param groupId the group ID
7507             * @param privateLayout the private layout
7508             * @param friendlyURL the friendly u r l
7509             * @param retrieveFromCache whether to retrieve from the finder cache
7510             * @return the matching layout, or <code>null</code> if a matching layout could not be found
7511             */
7512            @Override
7513            public Layout fetchByG_P_F(long groupId, boolean privateLayout,
7514                    String friendlyURL, boolean retrieveFromCache) {
7515                    Object[] finderArgs = new Object[] { groupId, privateLayout, friendlyURL };
7516    
7517                    Object result = null;
7518    
7519                    if (retrieveFromCache) {
7520                            result = finderCache.getResult(FINDER_PATH_FETCH_BY_G_P_F,
7521                                            finderArgs, this);
7522                    }
7523    
7524                    if (result instanceof Layout) {
7525                            Layout layout = (Layout)result;
7526    
7527                            if ((groupId != layout.getGroupId()) ||
7528                                            (privateLayout != layout.getPrivateLayout()) ||
7529                                            !Validator.equals(friendlyURL, layout.getFriendlyURL())) {
7530                                    result = null;
7531                            }
7532                    }
7533    
7534                    if (result == null) {
7535                            StringBundler query = new StringBundler(5);
7536    
7537                            query.append(_SQL_SELECT_LAYOUT_WHERE);
7538    
7539                            query.append(_FINDER_COLUMN_G_P_F_GROUPID_2);
7540    
7541                            query.append(_FINDER_COLUMN_G_P_F_PRIVATELAYOUT_2);
7542    
7543                            boolean bindFriendlyURL = false;
7544    
7545                            if (friendlyURL == null) {
7546                                    query.append(_FINDER_COLUMN_G_P_F_FRIENDLYURL_1);
7547                            }
7548                            else if (friendlyURL.equals(StringPool.BLANK)) {
7549                                    query.append(_FINDER_COLUMN_G_P_F_FRIENDLYURL_3);
7550                            }
7551                            else {
7552                                    bindFriendlyURL = true;
7553    
7554                                    query.append(_FINDER_COLUMN_G_P_F_FRIENDLYURL_2);
7555                            }
7556    
7557                            String sql = query.toString();
7558    
7559                            Session session = null;
7560    
7561                            try {
7562                                    session = openSession();
7563    
7564                                    Query q = session.createQuery(sql);
7565    
7566                                    QueryPos qPos = QueryPos.getInstance(q);
7567    
7568                                    qPos.add(groupId);
7569    
7570                                    qPos.add(privateLayout);
7571    
7572                                    if (bindFriendlyURL) {
7573                                            qPos.add(friendlyURL);
7574                                    }
7575    
7576                                    List<Layout> list = q.list();
7577    
7578                                    if (list.isEmpty()) {
7579                                            finderCache.putResult(FINDER_PATH_FETCH_BY_G_P_F,
7580                                                    finderArgs, list);
7581                                    }
7582                                    else {
7583                                            Layout layout = list.get(0);
7584    
7585                                            result = layout;
7586    
7587                                            cacheResult(layout);
7588    
7589                                            if ((layout.getGroupId() != groupId) ||
7590                                                            (layout.getPrivateLayout() != privateLayout) ||
7591                                                            (layout.getFriendlyURL() == null) ||
7592                                                            !layout.getFriendlyURL().equals(friendlyURL)) {
7593                                                    finderCache.putResult(FINDER_PATH_FETCH_BY_G_P_F,
7594                                                            finderArgs, layout);
7595                                            }
7596                                    }
7597                            }
7598                            catch (Exception e) {
7599                                    finderCache.removeResult(FINDER_PATH_FETCH_BY_G_P_F, finderArgs);
7600    
7601                                    throw processException(e);
7602                            }
7603                            finally {
7604                                    closeSession(session);
7605                            }
7606                    }
7607    
7608                    if (result instanceof List<?>) {
7609                            return null;
7610                    }
7611                    else {
7612                            return (Layout)result;
7613                    }
7614            }
7615    
7616            /**
7617             * Removes the layout where groupId = &#63; and privateLayout = &#63; and friendlyURL = &#63; from the database.
7618             *
7619             * @param groupId the group ID
7620             * @param privateLayout the private layout
7621             * @param friendlyURL the friendly u r l
7622             * @return the layout that was removed
7623             */
7624            @Override
7625            public Layout removeByG_P_F(long groupId, boolean privateLayout,
7626                    String friendlyURL) throws NoSuchLayoutException {
7627                    Layout layout = findByG_P_F(groupId, privateLayout, friendlyURL);
7628    
7629                    return remove(layout);
7630            }
7631    
7632            /**
7633             * Returns the number of layouts where groupId = &#63; and privateLayout = &#63; and friendlyURL = &#63;.
7634             *
7635             * @param groupId the group ID
7636             * @param privateLayout the private layout
7637             * @param friendlyURL the friendly u r l
7638             * @return the number of matching layouts
7639             */
7640            @Override
7641            public int countByG_P_F(long groupId, boolean privateLayout,
7642                    String friendlyURL) {
7643                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_P_F;
7644    
7645                    Object[] finderArgs = new Object[] { groupId, privateLayout, friendlyURL };
7646    
7647                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
7648    
7649                    if (count == null) {
7650                            StringBundler query = new StringBundler(4);
7651    
7652                            query.append(_SQL_COUNT_LAYOUT_WHERE);
7653    
7654                            query.append(_FINDER_COLUMN_G_P_F_GROUPID_2);
7655    
7656                            query.append(_FINDER_COLUMN_G_P_F_PRIVATELAYOUT_2);
7657    
7658                            boolean bindFriendlyURL = false;
7659    
7660                            if (friendlyURL == null) {
7661                                    query.append(_FINDER_COLUMN_G_P_F_FRIENDLYURL_1);
7662                            }
7663                            else if (friendlyURL.equals(StringPool.BLANK)) {
7664                                    query.append(_FINDER_COLUMN_G_P_F_FRIENDLYURL_3);
7665                            }
7666                            else {
7667                                    bindFriendlyURL = true;
7668    
7669                                    query.append(_FINDER_COLUMN_G_P_F_FRIENDLYURL_2);
7670                            }
7671    
7672                            String sql = query.toString();
7673    
7674                            Session session = null;
7675    
7676                            try {
7677                                    session = openSession();
7678    
7679                                    Query q = session.createQuery(sql);
7680    
7681                                    QueryPos qPos = QueryPos.getInstance(q);
7682    
7683                                    qPos.add(groupId);
7684    
7685                                    qPos.add(privateLayout);
7686    
7687                                    if (bindFriendlyURL) {
7688                                            qPos.add(friendlyURL);
7689                                    }
7690    
7691                                    count = (Long)q.uniqueResult();
7692    
7693                                    finderCache.putResult(finderPath, finderArgs, count);
7694                            }
7695                            catch (Exception e) {
7696                                    finderCache.removeResult(finderPath, finderArgs);
7697    
7698                                    throw processException(e);
7699                            }
7700                            finally {
7701                                    closeSession(session);
7702                            }
7703                    }
7704    
7705                    return count.intValue();
7706            }
7707    
7708            private static final String _FINDER_COLUMN_G_P_F_GROUPID_2 = "layout.groupId = ? AND ";
7709            private static final String _FINDER_COLUMN_G_P_F_PRIVATELAYOUT_2 = "layout.privateLayout = ? AND ";
7710            private static final String _FINDER_COLUMN_G_P_F_FRIENDLYURL_1 = "layout.friendlyURL IS NULL";
7711            private static final String _FINDER_COLUMN_G_P_F_FRIENDLYURL_2 = "layout.friendlyURL = ?";
7712            private static final String _FINDER_COLUMN_G_P_F_FRIENDLYURL_3 = "(layout.friendlyURL IS NULL OR layout.friendlyURL = '')";
7713            public static final FinderPath FINDER_PATH_FETCH_BY_G_P_SPLU = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
7714                            LayoutModelImpl.FINDER_CACHE_ENABLED, LayoutImpl.class,
7715                            FINDER_CLASS_NAME_ENTITY, "fetchByG_P_SPLU",
7716                            new String[] {
7717                                    Long.class.getName(), Boolean.class.getName(),
7718                                    String.class.getName()
7719                            },
7720                            LayoutModelImpl.GROUPID_COLUMN_BITMASK |
7721                            LayoutModelImpl.PRIVATELAYOUT_COLUMN_BITMASK |
7722                            LayoutModelImpl.SOURCEPROTOTYPELAYOUTUUID_COLUMN_BITMASK);
7723            public static final FinderPath FINDER_PATH_COUNT_BY_G_P_SPLU = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
7724                            LayoutModelImpl.FINDER_CACHE_ENABLED, Long.class,
7725                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P_SPLU",
7726                            new String[] {
7727                                    Long.class.getName(), Boolean.class.getName(),
7728                                    String.class.getName()
7729                            });
7730    
7731            /**
7732             * Returns the layout where groupId = &#63; and privateLayout = &#63; and sourcePrototypeLayoutUuid = &#63; or throws a {@link NoSuchLayoutException} if it could not be found.
7733             *
7734             * @param groupId the group ID
7735             * @param privateLayout the private layout
7736             * @param sourcePrototypeLayoutUuid the source prototype layout uuid
7737             * @return the matching layout
7738             * @throws NoSuchLayoutException if a matching layout could not be found
7739             */
7740            @Override
7741            public Layout findByG_P_SPLU(long groupId, boolean privateLayout,
7742                    String sourcePrototypeLayoutUuid) throws NoSuchLayoutException {
7743                    Layout layout = fetchByG_P_SPLU(groupId, privateLayout,
7744                                    sourcePrototypeLayoutUuid);
7745    
7746                    if (layout == null) {
7747                            StringBundler msg = new StringBundler(8);
7748    
7749                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7750    
7751                            msg.append("groupId=");
7752                            msg.append(groupId);
7753    
7754                            msg.append(", privateLayout=");
7755                            msg.append(privateLayout);
7756    
7757                            msg.append(", sourcePrototypeLayoutUuid=");
7758                            msg.append(sourcePrototypeLayoutUuid);
7759    
7760                            msg.append(StringPool.CLOSE_CURLY_BRACE);
7761    
7762                            if (_log.isWarnEnabled()) {
7763                                    _log.warn(msg.toString());
7764                            }
7765    
7766                            throw new NoSuchLayoutException(msg.toString());
7767                    }
7768    
7769                    return layout;
7770            }
7771    
7772            /**
7773             * Returns the layout where groupId = &#63; and privateLayout = &#63; and sourcePrototypeLayoutUuid = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
7774             *
7775             * @param groupId the group ID
7776             * @param privateLayout the private layout
7777             * @param sourcePrototypeLayoutUuid the source prototype layout uuid
7778             * @return the matching layout, or <code>null</code> if a matching layout could not be found
7779             */
7780            @Override
7781            public Layout fetchByG_P_SPLU(long groupId, boolean privateLayout,
7782                    String sourcePrototypeLayoutUuid) {
7783                    return fetchByG_P_SPLU(groupId, privateLayout,
7784                            sourcePrototypeLayoutUuid, true);
7785            }
7786    
7787            /**
7788             * Returns the layout where groupId = &#63; and privateLayout = &#63; and sourcePrototypeLayoutUuid = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
7789             *
7790             * @param groupId the group ID
7791             * @param privateLayout the private layout
7792             * @param sourcePrototypeLayoutUuid the source prototype layout uuid
7793             * @param retrieveFromCache whether to retrieve from the finder cache
7794             * @return the matching layout, or <code>null</code> if a matching layout could not be found
7795             */
7796            @Override
7797            public Layout fetchByG_P_SPLU(long groupId, boolean privateLayout,
7798                    String sourcePrototypeLayoutUuid, boolean retrieveFromCache) {
7799                    Object[] finderArgs = new Object[] {
7800                                    groupId, privateLayout, sourcePrototypeLayoutUuid
7801                            };
7802    
7803                    Object result = null;
7804    
7805                    if (retrieveFromCache) {
7806                            result = finderCache.getResult(FINDER_PATH_FETCH_BY_G_P_SPLU,
7807                                            finderArgs, this);
7808                    }
7809    
7810                    if (result instanceof Layout) {
7811                            Layout layout = (Layout)result;
7812    
7813                            if ((groupId != layout.getGroupId()) ||
7814                                            (privateLayout != layout.getPrivateLayout()) ||
7815                                            !Validator.equals(sourcePrototypeLayoutUuid,
7816                                                    layout.getSourcePrototypeLayoutUuid())) {
7817                                    result = null;
7818                            }
7819                    }
7820    
7821                    if (result == null) {
7822                            StringBundler query = new StringBundler(5);
7823    
7824                            query.append(_SQL_SELECT_LAYOUT_WHERE);
7825    
7826                            query.append(_FINDER_COLUMN_G_P_SPLU_GROUPID_2);
7827    
7828                            query.append(_FINDER_COLUMN_G_P_SPLU_PRIVATELAYOUT_2);
7829    
7830                            boolean bindSourcePrototypeLayoutUuid = false;
7831    
7832                            if (sourcePrototypeLayoutUuid == null) {
7833                                    query.append(_FINDER_COLUMN_G_P_SPLU_SOURCEPROTOTYPELAYOUTUUID_1);
7834                            }
7835                            else if (sourcePrototypeLayoutUuid.equals(StringPool.BLANK)) {
7836                                    query.append(_FINDER_COLUMN_G_P_SPLU_SOURCEPROTOTYPELAYOUTUUID_3);
7837                            }
7838                            else {
7839                                    bindSourcePrototypeLayoutUuid = true;
7840    
7841                                    query.append(_FINDER_COLUMN_G_P_SPLU_SOURCEPROTOTYPELAYOUTUUID_2);
7842                            }
7843    
7844                            String sql = query.toString();
7845    
7846                            Session session = null;
7847    
7848                            try {
7849                                    session = openSession();
7850    
7851                                    Query q = session.createQuery(sql);
7852    
7853                                    QueryPos qPos = QueryPos.getInstance(q);
7854    
7855                                    qPos.add(groupId);
7856    
7857                                    qPos.add(privateLayout);
7858    
7859                                    if (bindSourcePrototypeLayoutUuid) {
7860                                            qPos.add(sourcePrototypeLayoutUuid);
7861                                    }
7862    
7863                                    List<Layout> list = q.list();
7864    
7865                                    if (list.isEmpty()) {
7866                                            finderCache.putResult(FINDER_PATH_FETCH_BY_G_P_SPLU,
7867                                                    finderArgs, list);
7868                                    }
7869                                    else {
7870                                            if ((list.size() > 1) && _log.isWarnEnabled()) {
7871                                                    _log.warn(
7872                                                            "LayoutPersistenceImpl.fetchByG_P_SPLU(long, boolean, String, boolean) with parameters (" +
7873                                                            StringUtil.merge(finderArgs) +
7874                                                            ") 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.");
7875                                            }
7876    
7877                                            Layout layout = list.get(0);
7878    
7879                                            result = layout;
7880    
7881                                            cacheResult(layout);
7882    
7883                                            if ((layout.getGroupId() != groupId) ||
7884                                                            (layout.getPrivateLayout() != privateLayout) ||
7885                                                            (layout.getSourcePrototypeLayoutUuid() == null) ||
7886                                                            !layout.getSourcePrototypeLayoutUuid()
7887                                                                               .equals(sourcePrototypeLayoutUuid)) {
7888                                                    finderCache.putResult(FINDER_PATH_FETCH_BY_G_P_SPLU,
7889                                                            finderArgs, layout);
7890                                            }
7891                                    }
7892                            }
7893                            catch (Exception e) {
7894                                    finderCache.removeResult(FINDER_PATH_FETCH_BY_G_P_SPLU,
7895                                            finderArgs);
7896    
7897                                    throw processException(e);
7898                            }
7899                            finally {
7900                                    closeSession(session);
7901                            }
7902                    }
7903    
7904                    if (result instanceof List<?>) {
7905                            return null;
7906                    }
7907                    else {
7908                            return (Layout)result;
7909                    }
7910            }
7911    
7912            /**
7913             * Removes the layout where groupId = &#63; and privateLayout = &#63; and sourcePrototypeLayoutUuid = &#63; from the database.
7914             *
7915             * @param groupId the group ID
7916             * @param privateLayout the private layout
7917             * @param sourcePrototypeLayoutUuid the source prototype layout uuid
7918             * @return the layout that was removed
7919             */
7920            @Override
7921            public Layout removeByG_P_SPLU(long groupId, boolean privateLayout,
7922                    String sourcePrototypeLayoutUuid) throws NoSuchLayoutException {
7923                    Layout layout = findByG_P_SPLU(groupId, privateLayout,
7924                                    sourcePrototypeLayoutUuid);
7925    
7926                    return remove(layout);
7927            }
7928    
7929            /**
7930             * Returns the number of layouts where groupId = &#63; and privateLayout = &#63; and sourcePrototypeLayoutUuid = &#63;.
7931             *
7932             * @param groupId the group ID
7933             * @param privateLayout the private layout
7934             * @param sourcePrototypeLayoutUuid the source prototype layout uuid
7935             * @return the number of matching layouts
7936             */
7937            @Override
7938            public int countByG_P_SPLU(long groupId, boolean privateLayout,
7939                    String sourcePrototypeLayoutUuid) {
7940                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_P_SPLU;
7941    
7942                    Object[] finderArgs = new Object[] {
7943                                    groupId, privateLayout, sourcePrototypeLayoutUuid
7944                            };
7945    
7946                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
7947    
7948                    if (count == null) {
7949                            StringBundler query = new StringBundler(4);
7950    
7951                            query.append(_SQL_COUNT_LAYOUT_WHERE);
7952    
7953                            query.append(_FINDER_COLUMN_G_P_SPLU_GROUPID_2);
7954    
7955                            query.append(_FINDER_COLUMN_G_P_SPLU_PRIVATELAYOUT_2);
7956    
7957                            boolean bindSourcePrototypeLayoutUuid = false;
7958    
7959                            if (sourcePrototypeLayoutUuid == null) {
7960                                    query.append(_FINDER_COLUMN_G_P_SPLU_SOURCEPROTOTYPELAYOUTUUID_1);
7961                            }
7962                            else if (sourcePrototypeLayoutUuid.equals(StringPool.BLANK)) {
7963                                    query.append(_FINDER_COLUMN_G_P_SPLU_SOURCEPROTOTYPELAYOUTUUID_3);
7964                            }
7965                            else {
7966                                    bindSourcePrototypeLayoutUuid = true;
7967    
7968                                    query.append(_FINDER_COLUMN_G_P_SPLU_SOURCEPROTOTYPELAYOUTUUID_2);
7969                            }
7970    
7971                            String sql = query.toString();
7972    
7973                            Session session = null;
7974    
7975                            try {
7976                                    session = openSession();
7977    
7978                                    Query q = session.createQuery(sql);
7979    
7980                                    QueryPos qPos = QueryPos.getInstance(q);
7981    
7982                                    qPos.add(groupId);
7983    
7984                                    qPos.add(privateLayout);
7985    
7986                                    if (bindSourcePrototypeLayoutUuid) {
7987                                            qPos.add(sourcePrototypeLayoutUuid);
7988                                    }
7989    
7990                                    count = (Long)q.uniqueResult();
7991    
7992                                    finderCache.putResult(finderPath, finderArgs, count);
7993                            }
7994                            catch (Exception e) {
7995                                    finderCache.removeResult(finderPath, finderArgs);
7996    
7997                                    throw processException(e);
7998                            }
7999                            finally {
8000                                    closeSession(session);
8001                            }
8002                    }
8003    
8004                    return count.intValue();
8005            }
8006    
8007            private static final String _FINDER_COLUMN_G_P_SPLU_GROUPID_2 = "layout.groupId = ? AND ";
8008            private static final String _FINDER_COLUMN_G_P_SPLU_PRIVATELAYOUT_2 = "layout.privateLayout = ? AND ";
8009            private static final String _FINDER_COLUMN_G_P_SPLU_SOURCEPROTOTYPELAYOUTUUID_1 =
8010                    "layout.sourcePrototypeLayoutUuid IS NULL";
8011            private static final String _FINDER_COLUMN_G_P_SPLU_SOURCEPROTOTYPELAYOUTUUID_2 =
8012                    "layout.sourcePrototypeLayoutUuid = ?";
8013            private static final String _FINDER_COLUMN_G_P_SPLU_SOURCEPROTOTYPELAYOUTUUID_3 =
8014                    "(layout.sourcePrototypeLayoutUuid IS NULL OR layout.sourcePrototypeLayoutUuid = '')";
8015    
8016            public LayoutPersistenceImpl() {
8017                    setModelClass(Layout.class);
8018            }
8019    
8020            /**
8021             * Caches the layout in the entity cache if it is enabled.
8022             *
8023             * @param layout the layout
8024             */
8025            @Override
8026            public void cacheResult(Layout layout) {
8027                    entityCache.putResult(LayoutModelImpl.ENTITY_CACHE_ENABLED,
8028                            LayoutImpl.class, layout.getPrimaryKey(), layout);
8029    
8030                    finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G_P,
8031                            new Object[] {
8032                                    layout.getUuid(), layout.getGroupId(), layout.getPrivateLayout()
8033                            }, layout);
8034    
8035                    finderCache.putResult(FINDER_PATH_FETCH_BY_ICONIMAGEID,
8036                            new Object[] { layout.getIconImageId() }, layout);
8037    
8038                    finderCache.putResult(FINDER_PATH_FETCH_BY_G_P_L,
8039                            new Object[] {
8040                                    layout.getGroupId(), layout.getPrivateLayout(),
8041                                    layout.getLayoutId()
8042                            }, layout);
8043    
8044                    finderCache.putResult(FINDER_PATH_FETCH_BY_G_P_F,
8045                            new Object[] {
8046                                    layout.getGroupId(), layout.getPrivateLayout(),
8047                                    layout.getFriendlyURL()
8048                            }, layout);
8049    
8050                    finderCache.putResult(FINDER_PATH_FETCH_BY_G_P_SPLU,
8051                            new Object[] {
8052                                    layout.getGroupId(), layout.getPrivateLayout(),
8053                                    layout.getSourcePrototypeLayoutUuid()
8054                            }, layout);
8055    
8056                    layout.resetOriginalValues();
8057            }
8058    
8059            /**
8060             * Caches the layouts in the entity cache if it is enabled.
8061             *
8062             * @param layouts the layouts
8063             */
8064            @Override
8065            public void cacheResult(List<Layout> layouts) {
8066                    for (Layout layout : layouts) {
8067                            if (entityCache.getResult(LayoutModelImpl.ENTITY_CACHE_ENABLED,
8068                                                    LayoutImpl.class, layout.getPrimaryKey()) == null) {
8069                                    cacheResult(layout);
8070                            }
8071                            else {
8072                                    layout.resetOriginalValues();
8073                            }
8074                    }
8075            }
8076    
8077            /**
8078             * Clears the cache for all layouts.
8079             *
8080             * <p>
8081             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
8082             * </p>
8083             */
8084            @Override
8085            public void clearCache() {
8086                    entityCache.clearCache(LayoutImpl.class);
8087    
8088                    finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
8089                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
8090                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
8091            }
8092    
8093            /**
8094             * Clears the cache for the layout.
8095             *
8096             * <p>
8097             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
8098             * </p>
8099             */
8100            @Override
8101            public void clearCache(Layout layout) {
8102                    entityCache.removeResult(LayoutModelImpl.ENTITY_CACHE_ENABLED,
8103                            LayoutImpl.class, layout.getPrimaryKey());
8104    
8105                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
8106                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
8107    
8108                    clearUniqueFindersCache((LayoutModelImpl)layout);
8109            }
8110    
8111            @Override
8112            public void clearCache(List<Layout> layouts) {
8113                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
8114                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
8115    
8116                    for (Layout layout : layouts) {
8117                            entityCache.removeResult(LayoutModelImpl.ENTITY_CACHE_ENABLED,
8118                                    LayoutImpl.class, layout.getPrimaryKey());
8119    
8120                            clearUniqueFindersCache((LayoutModelImpl)layout);
8121                    }
8122            }
8123    
8124            protected void cacheUniqueFindersCache(LayoutModelImpl layoutModelImpl,
8125                    boolean isNew) {
8126                    if (isNew) {
8127                            Object[] args = new Object[] {
8128                                            layoutModelImpl.getUuid(), layoutModelImpl.getGroupId(),
8129                                            layoutModelImpl.getPrivateLayout()
8130                                    };
8131    
8132                            finderCache.putResult(FINDER_PATH_COUNT_BY_UUID_G_P, args,
8133                                    Long.valueOf(1));
8134                            finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G_P, args,
8135                                    layoutModelImpl);
8136    
8137                            args = new Object[] { layoutModelImpl.getIconImageId() };
8138    
8139                            finderCache.putResult(FINDER_PATH_COUNT_BY_ICONIMAGEID, args,
8140                                    Long.valueOf(1));
8141                            finderCache.putResult(FINDER_PATH_FETCH_BY_ICONIMAGEID, args,
8142                                    layoutModelImpl);
8143    
8144                            args = new Object[] {
8145                                            layoutModelImpl.getGroupId(),
8146                                            layoutModelImpl.getPrivateLayout(),
8147                                            layoutModelImpl.getLayoutId()
8148                                    };
8149    
8150                            finderCache.putResult(FINDER_PATH_COUNT_BY_G_P_L, args,
8151                                    Long.valueOf(1));
8152                            finderCache.putResult(FINDER_PATH_FETCH_BY_G_P_L, args,
8153                                    layoutModelImpl);
8154    
8155                            args = new Object[] {
8156                                            layoutModelImpl.getGroupId(),
8157                                            layoutModelImpl.getPrivateLayout(),
8158                                            layoutModelImpl.getFriendlyURL()
8159                                    };
8160    
8161                            finderCache.putResult(FINDER_PATH_COUNT_BY_G_P_F, args,
8162                                    Long.valueOf(1));
8163                            finderCache.putResult(FINDER_PATH_FETCH_BY_G_P_F, args,
8164                                    layoutModelImpl);
8165    
8166                            args = new Object[] {
8167                                            layoutModelImpl.getGroupId(),
8168                                            layoutModelImpl.getPrivateLayout(),
8169                                            layoutModelImpl.getSourcePrototypeLayoutUuid()
8170                                    };
8171    
8172                            finderCache.putResult(FINDER_PATH_COUNT_BY_G_P_SPLU, args,
8173                                    Long.valueOf(1));
8174                            finderCache.putResult(FINDER_PATH_FETCH_BY_G_P_SPLU, args,
8175                                    layoutModelImpl);
8176                    }
8177                    else {
8178                            if ((layoutModelImpl.getColumnBitmask() &
8179                                            FINDER_PATH_FETCH_BY_UUID_G_P.getColumnBitmask()) != 0) {
8180                                    Object[] args = new Object[] {
8181                                                    layoutModelImpl.getUuid(), layoutModelImpl.getGroupId(),
8182                                                    layoutModelImpl.getPrivateLayout()
8183                                            };
8184    
8185                                    finderCache.putResult(FINDER_PATH_COUNT_BY_UUID_G_P, args,
8186                                            Long.valueOf(1));
8187                                    finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G_P, args,
8188                                            layoutModelImpl);
8189                            }
8190    
8191                            if ((layoutModelImpl.getColumnBitmask() &
8192                                            FINDER_PATH_FETCH_BY_ICONIMAGEID.getColumnBitmask()) != 0) {
8193                                    Object[] args = new Object[] { layoutModelImpl.getIconImageId() };
8194    
8195                                    finderCache.putResult(FINDER_PATH_COUNT_BY_ICONIMAGEID, args,
8196                                            Long.valueOf(1));
8197                                    finderCache.putResult(FINDER_PATH_FETCH_BY_ICONIMAGEID, args,
8198                                            layoutModelImpl);
8199                            }
8200    
8201                            if ((layoutModelImpl.getColumnBitmask() &
8202                                            FINDER_PATH_FETCH_BY_G_P_L.getColumnBitmask()) != 0) {
8203                                    Object[] args = new Object[] {
8204                                                    layoutModelImpl.getGroupId(),
8205                                                    layoutModelImpl.getPrivateLayout(),
8206                                                    layoutModelImpl.getLayoutId()
8207                                            };
8208    
8209                                    finderCache.putResult(FINDER_PATH_COUNT_BY_G_P_L, args,
8210                                            Long.valueOf(1));
8211                                    finderCache.putResult(FINDER_PATH_FETCH_BY_G_P_L, args,
8212                                            layoutModelImpl);
8213                            }
8214    
8215                            if ((layoutModelImpl.getColumnBitmask() &
8216                                            FINDER_PATH_FETCH_BY_G_P_F.getColumnBitmask()) != 0) {
8217                                    Object[] args = new Object[] {
8218                                                    layoutModelImpl.getGroupId(),
8219                                                    layoutModelImpl.getPrivateLayout(),
8220                                                    layoutModelImpl.getFriendlyURL()
8221                                            };
8222    
8223                                    finderCache.putResult(FINDER_PATH_COUNT_BY_G_P_F, args,
8224                                            Long.valueOf(1));
8225                                    finderCache.putResult(FINDER_PATH_FETCH_BY_G_P_F, args,
8226                                            layoutModelImpl);
8227                            }
8228    
8229                            if ((layoutModelImpl.getColumnBitmask() &
8230                                            FINDER_PATH_FETCH_BY_G_P_SPLU.getColumnBitmask()) != 0) {
8231                                    Object[] args = new Object[] {
8232                                                    layoutModelImpl.getGroupId(),
8233                                                    layoutModelImpl.getPrivateLayout(),
8234                                                    layoutModelImpl.getSourcePrototypeLayoutUuid()
8235                                            };
8236    
8237                                    finderCache.putResult(FINDER_PATH_COUNT_BY_G_P_SPLU, args,
8238                                            Long.valueOf(1));
8239                                    finderCache.putResult(FINDER_PATH_FETCH_BY_G_P_SPLU, args,
8240                                            layoutModelImpl);
8241                            }
8242                    }
8243            }
8244    
8245            protected void clearUniqueFindersCache(LayoutModelImpl layoutModelImpl) {
8246                    Object[] args = new Object[] {
8247                                    layoutModelImpl.getUuid(), layoutModelImpl.getGroupId(),
8248                                    layoutModelImpl.getPrivateLayout()
8249                            };
8250    
8251                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_G_P, args);
8252                    finderCache.removeResult(FINDER_PATH_FETCH_BY_UUID_G_P, args);
8253    
8254                    if ((layoutModelImpl.getColumnBitmask() &
8255                                    FINDER_PATH_FETCH_BY_UUID_G_P.getColumnBitmask()) != 0) {
8256                            args = new Object[] {
8257                                            layoutModelImpl.getOriginalUuid(),
8258                                            layoutModelImpl.getOriginalGroupId(),
8259                                            layoutModelImpl.getOriginalPrivateLayout()
8260                                    };
8261    
8262                            finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_G_P, args);
8263                            finderCache.removeResult(FINDER_PATH_FETCH_BY_UUID_G_P, args);
8264                    }
8265    
8266                    args = new Object[] { layoutModelImpl.getIconImageId() };
8267    
8268                    finderCache.removeResult(FINDER_PATH_COUNT_BY_ICONIMAGEID, args);
8269                    finderCache.removeResult(FINDER_PATH_FETCH_BY_ICONIMAGEID, args);
8270    
8271                    if ((layoutModelImpl.getColumnBitmask() &
8272                                    FINDER_PATH_FETCH_BY_ICONIMAGEID.getColumnBitmask()) != 0) {
8273                            args = new Object[] { layoutModelImpl.getOriginalIconImageId() };
8274    
8275                            finderCache.removeResult(FINDER_PATH_COUNT_BY_ICONIMAGEID, args);
8276                            finderCache.removeResult(FINDER_PATH_FETCH_BY_ICONIMAGEID, args);
8277                    }
8278    
8279                    args = new Object[] {
8280                                    layoutModelImpl.getGroupId(), layoutModelImpl.getPrivateLayout(),
8281                                    layoutModelImpl.getLayoutId()
8282                            };
8283    
8284                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_P_L, args);
8285                    finderCache.removeResult(FINDER_PATH_FETCH_BY_G_P_L, args);
8286    
8287                    if ((layoutModelImpl.getColumnBitmask() &
8288                                    FINDER_PATH_FETCH_BY_G_P_L.getColumnBitmask()) != 0) {
8289                            args = new Object[] {
8290                                            layoutModelImpl.getOriginalGroupId(),
8291                                            layoutModelImpl.getOriginalPrivateLayout(),
8292                                            layoutModelImpl.getOriginalLayoutId()
8293                                    };
8294    
8295                            finderCache.removeResult(FINDER_PATH_COUNT_BY_G_P_L, args);
8296                            finderCache.removeResult(FINDER_PATH_FETCH_BY_G_P_L, args);
8297                    }
8298    
8299                    args = new Object[] {
8300                                    layoutModelImpl.getGroupId(), layoutModelImpl.getPrivateLayout(),
8301                                    layoutModelImpl.getFriendlyURL()
8302                            };
8303    
8304                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_P_F, args);
8305                    finderCache.removeResult(FINDER_PATH_FETCH_BY_G_P_F, args);
8306    
8307                    if ((layoutModelImpl.getColumnBitmask() &
8308                                    FINDER_PATH_FETCH_BY_G_P_F.getColumnBitmask()) != 0) {
8309                            args = new Object[] {
8310                                            layoutModelImpl.getOriginalGroupId(),
8311                                            layoutModelImpl.getOriginalPrivateLayout(),
8312                                            layoutModelImpl.getOriginalFriendlyURL()
8313                                    };
8314    
8315                            finderCache.removeResult(FINDER_PATH_COUNT_BY_G_P_F, args);
8316                            finderCache.removeResult(FINDER_PATH_FETCH_BY_G_P_F, args);
8317                    }
8318    
8319                    args = new Object[] {
8320                                    layoutModelImpl.getGroupId(), layoutModelImpl.getPrivateLayout(),
8321                                    layoutModelImpl.getSourcePrototypeLayoutUuid()
8322                            };
8323    
8324                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_P_SPLU, args);
8325                    finderCache.removeResult(FINDER_PATH_FETCH_BY_G_P_SPLU, args);
8326    
8327                    if ((layoutModelImpl.getColumnBitmask() &
8328                                    FINDER_PATH_FETCH_BY_G_P_SPLU.getColumnBitmask()) != 0) {
8329                            args = new Object[] {
8330                                            layoutModelImpl.getOriginalGroupId(),
8331                                            layoutModelImpl.getOriginalPrivateLayout(),
8332                                            layoutModelImpl.getOriginalSourcePrototypeLayoutUuid()
8333                                    };
8334    
8335                            finderCache.removeResult(FINDER_PATH_COUNT_BY_G_P_SPLU, args);
8336                            finderCache.removeResult(FINDER_PATH_FETCH_BY_G_P_SPLU, args);
8337                    }
8338            }
8339    
8340            /**
8341             * Creates a new layout with the primary key. Does not add the layout to the database.
8342             *
8343             * @param plid the primary key for the new layout
8344             * @return the new layout
8345             */
8346            @Override
8347            public Layout create(long plid) {
8348                    Layout layout = new LayoutImpl();
8349    
8350                    layout.setNew(true);
8351                    layout.setPrimaryKey(plid);
8352    
8353                    String uuid = PortalUUIDUtil.generate();
8354    
8355                    layout.setUuid(uuid);
8356    
8357                    return layout;
8358            }
8359    
8360            /**
8361             * Removes the layout with the primary key from the database. Also notifies the appropriate model listeners.
8362             *
8363             * @param plid the primary key of the layout
8364             * @return the layout that was removed
8365             * @throws NoSuchLayoutException if a layout with the primary key could not be found
8366             */
8367            @Override
8368            public Layout remove(long plid) throws NoSuchLayoutException {
8369                    return remove((Serializable)plid);
8370            }
8371    
8372            /**
8373             * Removes the layout with the primary key from the database. Also notifies the appropriate model listeners.
8374             *
8375             * @param primaryKey the primary key of the layout
8376             * @return the layout that was removed
8377             * @throws NoSuchLayoutException if a layout with the primary key could not be found
8378             */
8379            @Override
8380            public Layout remove(Serializable primaryKey) throws NoSuchLayoutException {
8381                    Session session = null;
8382    
8383                    try {
8384                            session = openSession();
8385    
8386                            Layout layout = (Layout)session.get(LayoutImpl.class, primaryKey);
8387    
8388                            if (layout == null) {
8389                                    if (_log.isWarnEnabled()) {
8390                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
8391                                    }
8392    
8393                                    throw new NoSuchLayoutException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
8394                                            primaryKey);
8395                            }
8396    
8397                            return remove(layout);
8398                    }
8399                    catch (NoSuchLayoutException nsee) {
8400                            throw nsee;
8401                    }
8402                    catch (Exception e) {
8403                            throw processException(e);
8404                    }
8405                    finally {
8406                            closeSession(session);
8407                    }
8408            }
8409    
8410            @Override
8411            protected Layout removeImpl(Layout layout) {
8412                    layout = toUnwrappedModel(layout);
8413    
8414                    Session session = null;
8415    
8416                    try {
8417                            session = openSession();
8418    
8419                            if (!session.contains(layout)) {
8420                                    layout = (Layout)session.get(LayoutImpl.class,
8421                                                    layout.getPrimaryKeyObj());
8422                            }
8423    
8424                            if (layout != null) {
8425                                    session.delete(layout);
8426                            }
8427                    }
8428                    catch (Exception e) {
8429                            throw processException(e);
8430                    }
8431                    finally {
8432                            closeSession(session);
8433                    }
8434    
8435                    if (layout != null) {
8436                            clearCache(layout);
8437                    }
8438    
8439                    return layout;
8440            }
8441    
8442            @Override
8443            public Layout updateImpl(Layout layout) {
8444                    layout = toUnwrappedModel(layout);
8445    
8446                    boolean isNew = layout.isNew();
8447    
8448                    LayoutModelImpl layoutModelImpl = (LayoutModelImpl)layout;
8449    
8450                    if (Validator.isNull(layout.getUuid())) {
8451                            String uuid = PortalUUIDUtil.generate();
8452    
8453                            layout.setUuid(uuid);
8454                    }
8455    
8456                    ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();
8457    
8458                    Date now = new Date();
8459    
8460                    if (isNew && (layout.getCreateDate() == null)) {
8461                            if (serviceContext == null) {
8462                                    layout.setCreateDate(now);
8463                            }
8464                            else {
8465                                    layout.setCreateDate(serviceContext.getCreateDate(now));
8466                            }
8467                    }
8468    
8469                    if (!layoutModelImpl.hasSetModifiedDate()) {
8470                            if (serviceContext == null) {
8471                                    layout.setModifiedDate(now);
8472                            }
8473                            else {
8474                                    layout.setModifiedDate(serviceContext.getModifiedDate(now));
8475                            }
8476                    }
8477    
8478                    Session session = null;
8479    
8480                    try {
8481                            session = openSession();
8482    
8483                            if (layout.isNew()) {
8484                                    session.save(layout);
8485    
8486                                    layout.setNew(false);
8487                            }
8488                            else {
8489                                    layout = (Layout)session.merge(layout);
8490                            }
8491                    }
8492                    catch (Exception e) {
8493                            throw processException(e);
8494                    }
8495                    finally {
8496                            closeSession(session);
8497                    }
8498    
8499                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
8500    
8501                    if (isNew || !LayoutModelImpl.COLUMN_BITMASK_ENABLED) {
8502                            finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
8503                    }
8504    
8505                    else {
8506                            if ((layoutModelImpl.getColumnBitmask() &
8507                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
8508                                    Object[] args = new Object[] { layoutModelImpl.getOriginalUuid() };
8509    
8510                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
8511                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
8512                                            args);
8513    
8514                                    args = new Object[] { layoutModelImpl.getUuid() };
8515    
8516                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
8517                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
8518                                            args);
8519                            }
8520    
8521                            if ((layoutModelImpl.getColumnBitmask() &
8522                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
8523                                    Object[] args = new Object[] {
8524                                                    layoutModelImpl.getOriginalUuid(),
8525                                                    layoutModelImpl.getOriginalCompanyId()
8526                                            };
8527    
8528                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
8529                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
8530                                            args);
8531    
8532                                    args = new Object[] {
8533                                                    layoutModelImpl.getUuid(),
8534                                                    layoutModelImpl.getCompanyId()
8535                                            };
8536    
8537                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
8538                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
8539                                            args);
8540                            }
8541    
8542                            if ((layoutModelImpl.getColumnBitmask() &
8543                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
8544                                    Object[] args = new Object[] {
8545                                                    layoutModelImpl.getOriginalGroupId()
8546                                            };
8547    
8548                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
8549                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
8550                                            args);
8551    
8552                                    args = new Object[] { layoutModelImpl.getGroupId() };
8553    
8554                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
8555                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
8556                                            args);
8557                            }
8558    
8559                            if ((layoutModelImpl.getColumnBitmask() &
8560                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
8561                                    Object[] args = new Object[] {
8562                                                    layoutModelImpl.getOriginalCompanyId()
8563                                            };
8564    
8565                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_COMPANYID, args);
8566                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
8567                                            args);
8568    
8569                                    args = new Object[] { layoutModelImpl.getCompanyId() };
8570    
8571                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_COMPANYID, args);
8572                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
8573                                            args);
8574                            }
8575    
8576                            if ((layoutModelImpl.getColumnBitmask() &
8577                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LAYOUTPROTOTYPEUUID.getColumnBitmask()) != 0) {
8578                                    Object[] args = new Object[] {
8579                                                    layoutModelImpl.getOriginalLayoutPrototypeUuid()
8580                                            };
8581    
8582                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_LAYOUTPROTOTYPEUUID,
8583                                            args);
8584                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LAYOUTPROTOTYPEUUID,
8585                                            args);
8586    
8587                                    args = new Object[] { layoutModelImpl.getLayoutPrototypeUuid() };
8588    
8589                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_LAYOUTPROTOTYPEUUID,
8590                                            args);
8591                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LAYOUTPROTOTYPEUUID,
8592                                            args);
8593                            }
8594    
8595                            if ((layoutModelImpl.getColumnBitmask() &
8596                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SOURCEPROTOTYPELAYOUTUUID.getColumnBitmask()) != 0) {
8597                                    Object[] args = new Object[] {
8598                                                    layoutModelImpl.getOriginalSourcePrototypeLayoutUuid()
8599                                            };
8600    
8601                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_SOURCEPROTOTYPELAYOUTUUID,
8602                                            args);
8603                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SOURCEPROTOTYPELAYOUTUUID,
8604                                            args);
8605    
8606                                    args = new Object[] {
8607                                                    layoutModelImpl.getSourcePrototypeLayoutUuid()
8608                                            };
8609    
8610                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_SOURCEPROTOTYPELAYOUTUUID,
8611                                            args);
8612                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SOURCEPROTOTYPELAYOUTUUID,
8613                                            args);
8614                            }
8615    
8616                            if ((layoutModelImpl.getColumnBitmask() &
8617                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P.getColumnBitmask()) != 0) {
8618                                    Object[] args = new Object[] {
8619                                                    layoutModelImpl.getOriginalGroupId(),
8620                                                    layoutModelImpl.getOriginalPrivateLayout()
8621                                            };
8622    
8623                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_P, args);
8624                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P,
8625                                            args);
8626    
8627                                    args = new Object[] {
8628                                                    layoutModelImpl.getGroupId(),
8629                                                    layoutModelImpl.getPrivateLayout()
8630                                            };
8631    
8632                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_P, args);
8633                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P,
8634                                            args);
8635                            }
8636    
8637                            if ((layoutModelImpl.getColumnBitmask() &
8638                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_P.getColumnBitmask()) != 0) {
8639                                    Object[] args = new Object[] {
8640                                                    layoutModelImpl.getOriginalGroupId(),
8641                                                    layoutModelImpl.getOriginalPrivateLayout(),
8642                                                    layoutModelImpl.getOriginalParentLayoutId()
8643                                            };
8644    
8645                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_P_P, args);
8646                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_P,
8647                                            args);
8648    
8649                                    args = new Object[] {
8650                                                    layoutModelImpl.getGroupId(),
8651                                                    layoutModelImpl.getPrivateLayout(),
8652                                                    layoutModelImpl.getParentLayoutId()
8653                                            };
8654    
8655                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_P_P, args);
8656                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_P,
8657                                            args);
8658                            }
8659    
8660                            if ((layoutModelImpl.getColumnBitmask() &
8661                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_T.getColumnBitmask()) != 0) {
8662                                    Object[] args = new Object[] {
8663                                                    layoutModelImpl.getOriginalGroupId(),
8664                                                    layoutModelImpl.getOriginalPrivateLayout(),
8665                                                    layoutModelImpl.getOriginalType()
8666                                            };
8667    
8668                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_P_T, args);
8669                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_T,
8670                                            args);
8671    
8672                                    args = new Object[] {
8673                                                    layoutModelImpl.getGroupId(),
8674                                                    layoutModelImpl.getPrivateLayout(),
8675                                                    layoutModelImpl.getType()
8676                                            };
8677    
8678                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_P_T, args);
8679                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_T,
8680                                            args);
8681                            }
8682                    }
8683    
8684                    entityCache.putResult(LayoutModelImpl.ENTITY_CACHE_ENABLED,
8685                            LayoutImpl.class, layout.getPrimaryKey(), layout, false);
8686    
8687                    clearUniqueFindersCache(layoutModelImpl);
8688                    cacheUniqueFindersCache(layoutModelImpl, isNew);
8689    
8690                    layout.resetOriginalValues();
8691    
8692                    return layout;
8693            }
8694    
8695            protected Layout toUnwrappedModel(Layout layout) {
8696                    if (layout instanceof LayoutImpl) {
8697                            return layout;
8698                    }
8699    
8700                    LayoutImpl layoutImpl = new LayoutImpl();
8701    
8702                    layoutImpl.setNew(layout.isNew());
8703                    layoutImpl.setPrimaryKey(layout.getPrimaryKey());
8704    
8705                    layoutImpl.setMvccVersion(layout.getMvccVersion());
8706                    layoutImpl.setUuid(layout.getUuid());
8707                    layoutImpl.setPlid(layout.getPlid());
8708                    layoutImpl.setGroupId(layout.getGroupId());
8709                    layoutImpl.setCompanyId(layout.getCompanyId());
8710                    layoutImpl.setUserId(layout.getUserId());
8711                    layoutImpl.setUserName(layout.getUserName());
8712                    layoutImpl.setCreateDate(layout.getCreateDate());
8713                    layoutImpl.setModifiedDate(layout.getModifiedDate());
8714                    layoutImpl.setPrivateLayout(layout.isPrivateLayout());
8715                    layoutImpl.setLayoutId(layout.getLayoutId());
8716                    layoutImpl.setParentLayoutId(layout.getParentLayoutId());
8717                    layoutImpl.setName(layout.getName());
8718                    layoutImpl.setTitle(layout.getTitle());
8719                    layoutImpl.setDescription(layout.getDescription());
8720                    layoutImpl.setKeywords(layout.getKeywords());
8721                    layoutImpl.setRobots(layout.getRobots());
8722                    layoutImpl.setType(layout.getType());
8723                    layoutImpl.setTypeSettings(layout.getTypeSettings());
8724                    layoutImpl.setHidden(layout.isHidden());
8725                    layoutImpl.setFriendlyURL(layout.getFriendlyURL());
8726                    layoutImpl.setIconImageId(layout.getIconImageId());
8727                    layoutImpl.setThemeId(layout.getThemeId());
8728                    layoutImpl.setColorSchemeId(layout.getColorSchemeId());
8729                    layoutImpl.setWapThemeId(layout.getWapThemeId());
8730                    layoutImpl.setWapColorSchemeId(layout.getWapColorSchemeId());
8731                    layoutImpl.setCss(layout.getCss());
8732                    layoutImpl.setPriority(layout.getPriority());
8733                    layoutImpl.setLayoutPrototypeUuid(layout.getLayoutPrototypeUuid());
8734                    layoutImpl.setLayoutPrototypeLinkEnabled(layout.isLayoutPrototypeLinkEnabled());
8735                    layoutImpl.setSourcePrototypeLayoutUuid(layout.getSourcePrototypeLayoutUuid());
8736                    layoutImpl.setLastPublishDate(layout.getLastPublishDate());
8737    
8738                    return layoutImpl;
8739            }
8740    
8741            /**
8742             * Returns the layout with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
8743             *
8744             * @param primaryKey the primary key of the layout
8745             * @return the layout
8746             * @throws NoSuchLayoutException if a layout with the primary key could not be found
8747             */
8748            @Override
8749            public Layout findByPrimaryKey(Serializable primaryKey)
8750                    throws NoSuchLayoutException {
8751                    Layout layout = fetchByPrimaryKey(primaryKey);
8752    
8753                    if (layout == null) {
8754                            if (_log.isWarnEnabled()) {
8755                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
8756                            }
8757    
8758                            throw new NoSuchLayoutException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
8759                                    primaryKey);
8760                    }
8761    
8762                    return layout;
8763            }
8764    
8765            /**
8766             * Returns the layout with the primary key or throws a {@link NoSuchLayoutException} if it could not be found.
8767             *
8768             * @param plid the primary key of the layout
8769             * @return the layout
8770             * @throws NoSuchLayoutException if a layout with the primary key could not be found
8771             */
8772            @Override
8773            public Layout findByPrimaryKey(long plid) throws NoSuchLayoutException {
8774                    return findByPrimaryKey((Serializable)plid);
8775            }
8776    
8777            /**
8778             * Returns the layout with the primary key or returns <code>null</code> if it could not be found.
8779             *
8780             * @param primaryKey the primary key of the layout
8781             * @return the layout, or <code>null</code> if a layout with the primary key could not be found
8782             */
8783            @Override
8784            public Layout fetchByPrimaryKey(Serializable primaryKey) {
8785                    Layout layout = (Layout)entityCache.getResult(LayoutModelImpl.ENTITY_CACHE_ENABLED,
8786                                    LayoutImpl.class, primaryKey);
8787    
8788                    if (layout == _nullLayout) {
8789                            return null;
8790                    }
8791    
8792                    if (layout == null) {
8793                            Session session = null;
8794    
8795                            try {
8796                                    session = openSession();
8797    
8798                                    layout = (Layout)session.get(LayoutImpl.class, primaryKey);
8799    
8800                                    if (layout != null) {
8801                                            cacheResult(layout);
8802                                    }
8803                                    else {
8804                                            entityCache.putResult(LayoutModelImpl.ENTITY_CACHE_ENABLED,
8805                                                    LayoutImpl.class, primaryKey, _nullLayout);
8806                                    }
8807                            }
8808                            catch (Exception e) {
8809                                    entityCache.removeResult(LayoutModelImpl.ENTITY_CACHE_ENABLED,
8810                                            LayoutImpl.class, primaryKey);
8811    
8812                                    throw processException(e);
8813                            }
8814                            finally {
8815                                    closeSession(session);
8816                            }
8817                    }
8818    
8819                    return layout;
8820            }
8821    
8822            /**
8823             * Returns the layout with the primary key or returns <code>null</code> if it could not be found.
8824             *
8825             * @param plid the primary key of the layout
8826             * @return the layout, or <code>null</code> if a layout with the primary key could not be found
8827             */
8828            @Override
8829            public Layout fetchByPrimaryKey(long plid) {
8830                    return fetchByPrimaryKey((Serializable)plid);
8831            }
8832    
8833            @Override
8834            public Map<Serializable, Layout> fetchByPrimaryKeys(
8835                    Set<Serializable> primaryKeys) {
8836                    if (primaryKeys.isEmpty()) {
8837                            return Collections.emptyMap();
8838                    }
8839    
8840                    Map<Serializable, Layout> map = new HashMap<Serializable, Layout>();
8841    
8842                    if (primaryKeys.size() == 1) {
8843                            Iterator<Serializable> iterator = primaryKeys.iterator();
8844    
8845                            Serializable primaryKey = iterator.next();
8846    
8847                            Layout layout = fetchByPrimaryKey(primaryKey);
8848    
8849                            if (layout != null) {
8850                                    map.put(primaryKey, layout);
8851                            }
8852    
8853                            return map;
8854                    }
8855    
8856                    Set<Serializable> uncachedPrimaryKeys = null;
8857    
8858                    for (Serializable primaryKey : primaryKeys) {
8859                            Layout layout = (Layout)entityCache.getResult(LayoutModelImpl.ENTITY_CACHE_ENABLED,
8860                                            LayoutImpl.class, primaryKey);
8861    
8862                            if (layout == null) {
8863                                    if (uncachedPrimaryKeys == null) {
8864                                            uncachedPrimaryKeys = new HashSet<Serializable>();
8865                                    }
8866    
8867                                    uncachedPrimaryKeys.add(primaryKey);
8868                            }
8869                            else {
8870                                    map.put(primaryKey, layout);
8871                            }
8872                    }
8873    
8874                    if (uncachedPrimaryKeys == null) {
8875                            return map;
8876                    }
8877    
8878                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
8879                                    1);
8880    
8881                    query.append(_SQL_SELECT_LAYOUT_WHERE_PKS_IN);
8882    
8883                    for (Serializable primaryKey : uncachedPrimaryKeys) {
8884                            query.append(String.valueOf(primaryKey));
8885    
8886                            query.append(StringPool.COMMA);
8887                    }
8888    
8889                    query.setIndex(query.index() - 1);
8890    
8891                    query.append(StringPool.CLOSE_PARENTHESIS);
8892    
8893                    String sql = query.toString();
8894    
8895                    Session session = null;
8896    
8897                    try {
8898                            session = openSession();
8899    
8900                            Query q = session.createQuery(sql);
8901    
8902                            for (Layout layout : (List<Layout>)q.list()) {
8903                                    map.put(layout.getPrimaryKeyObj(), layout);
8904    
8905                                    cacheResult(layout);
8906    
8907                                    uncachedPrimaryKeys.remove(layout.getPrimaryKeyObj());
8908                            }
8909    
8910                            for (Serializable primaryKey : uncachedPrimaryKeys) {
8911                                    entityCache.putResult(LayoutModelImpl.ENTITY_CACHE_ENABLED,
8912                                            LayoutImpl.class, primaryKey, _nullLayout);
8913                            }
8914                    }
8915                    catch (Exception e) {
8916                            throw processException(e);
8917                    }
8918                    finally {
8919                            closeSession(session);
8920                    }
8921    
8922                    return map;
8923            }
8924    
8925            /**
8926             * Returns all the layouts.
8927             *
8928             * @return the layouts
8929             */
8930            @Override
8931            public List<Layout> findAll() {
8932                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
8933            }
8934    
8935            /**
8936             * Returns a range of all the layouts.
8937             *
8938             * <p>
8939             * 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 LayoutModelImpl}. 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.
8940             * </p>
8941             *
8942             * @param start the lower bound of the range of layouts
8943             * @param end the upper bound of the range of layouts (not inclusive)
8944             * @return the range of layouts
8945             */
8946            @Override
8947            public List<Layout> findAll(int start, int end) {
8948                    return findAll(start, end, null);
8949            }
8950    
8951            /**
8952             * Returns an ordered range of all the layouts.
8953             *
8954             * <p>
8955             * 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 LayoutModelImpl}. 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.
8956             * </p>
8957             *
8958             * @param start the lower bound of the range of layouts
8959             * @param end the upper bound of the range of layouts (not inclusive)
8960             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8961             * @return the ordered range of layouts
8962             */
8963            @Override
8964            public List<Layout> findAll(int start, int end,
8965                    OrderByComparator<Layout> orderByComparator) {
8966                    return findAll(start, end, orderByComparator, true);
8967            }
8968    
8969            /**
8970             * Returns an ordered range of all the layouts.
8971             *
8972             * <p>
8973             * 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 LayoutModelImpl}. 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.
8974             * </p>
8975             *
8976             * @param start the lower bound of the range of layouts
8977             * @param end the upper bound of the range of layouts (not inclusive)
8978             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8979             * @param retrieveFromCache whether to retrieve from the finder cache
8980             * @return the ordered range of layouts
8981             */
8982            @Override
8983            public List<Layout> findAll(int start, int end,
8984                    OrderByComparator<Layout> orderByComparator, boolean retrieveFromCache) {
8985                    boolean pagination = true;
8986                    FinderPath finderPath = null;
8987                    Object[] finderArgs = null;
8988    
8989                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8990                                    (orderByComparator == null)) {
8991                            pagination = false;
8992                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
8993                            finderArgs = FINDER_ARGS_EMPTY;
8994                    }
8995                    else {
8996                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
8997                            finderArgs = new Object[] { start, end, orderByComparator };
8998                    }
8999    
9000                    List<Layout> list = null;
9001    
9002                    if (retrieveFromCache) {
9003                            list = (List<Layout>)finderCache.getResult(finderPath, finderArgs,
9004                                            this);
9005                    }
9006    
9007                    if (list == null) {
9008                            StringBundler query = null;
9009                            String sql = null;
9010    
9011                            if (orderByComparator != null) {
9012                                    query = new StringBundler(2 +
9013                                                    (orderByComparator.getOrderByFields().length * 3));
9014    
9015                                    query.append(_SQL_SELECT_LAYOUT);
9016    
9017                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9018                                            orderByComparator);
9019    
9020                                    sql = query.toString();
9021                            }
9022                            else {
9023                                    sql = _SQL_SELECT_LAYOUT;
9024    
9025                                    if (pagination) {
9026                                            sql = sql.concat(LayoutModelImpl.ORDER_BY_JPQL);
9027                                    }
9028                            }
9029    
9030                            Session session = null;
9031    
9032                            try {
9033                                    session = openSession();
9034    
9035                                    Query q = session.createQuery(sql);
9036    
9037                                    if (!pagination) {
9038                                            list = (List<Layout>)QueryUtil.list(q, getDialect(), start,
9039                                                            end, false);
9040    
9041                                            Collections.sort(list);
9042    
9043                                            list = Collections.unmodifiableList(list);
9044                                    }
9045                                    else {
9046                                            list = (List<Layout>)QueryUtil.list(q, getDialect(), start,
9047                                                            end);
9048                                    }
9049    
9050                                    cacheResult(list);
9051    
9052                                    finderCache.putResult(finderPath, finderArgs, list);
9053                            }
9054                            catch (Exception e) {
9055                                    finderCache.removeResult(finderPath, finderArgs);
9056    
9057                                    throw processException(e);
9058                            }
9059                            finally {
9060                                    closeSession(session);
9061                            }
9062                    }
9063    
9064                    return list;
9065            }
9066    
9067            /**
9068             * Removes all the layouts from the database.
9069             *
9070             */
9071            @Override
9072            public void removeAll() {
9073                    for (Layout layout : findAll()) {
9074                            remove(layout);
9075                    }
9076            }
9077    
9078            /**
9079             * Returns the number of layouts.
9080             *
9081             * @return the number of layouts
9082             */
9083            @Override
9084            public int countAll() {
9085                    Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
9086                                    FINDER_ARGS_EMPTY, this);
9087    
9088                    if (count == null) {
9089                            Session session = null;
9090    
9091                            try {
9092                                    session = openSession();
9093    
9094                                    Query q = session.createQuery(_SQL_COUNT_LAYOUT);
9095    
9096                                    count = (Long)q.uniqueResult();
9097    
9098                                    finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
9099                                            count);
9100                            }
9101                            catch (Exception e) {
9102                                    finderCache.removeResult(FINDER_PATH_COUNT_ALL,
9103                                            FINDER_ARGS_EMPTY);
9104    
9105                                    throw processException(e);
9106                            }
9107                            finally {
9108                                    closeSession(session);
9109                            }
9110                    }
9111    
9112                    return count.intValue();
9113            }
9114    
9115            @Override
9116            public Set<String> getBadColumnNames() {
9117                    return _badColumnNames;
9118            }
9119    
9120            @Override
9121            protected Map<String, Integer> getTableColumnsMap() {
9122                    return LayoutModelImpl.TABLE_COLUMNS_MAP;
9123            }
9124    
9125            /**
9126             * Initializes the layout persistence.
9127             */
9128            public void afterPropertiesSet() {
9129            }
9130    
9131            public void destroy() {
9132                    entityCache.removeCache(LayoutImpl.class.getName());
9133                    finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
9134                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
9135                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
9136            }
9137    
9138            @BeanReference(type = CompanyProvider.class)
9139            protected CompanyProvider companyProvider;
9140            protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
9141            protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
9142            private static final String _SQL_SELECT_LAYOUT = "SELECT layout FROM Layout layout";
9143            private static final String _SQL_SELECT_LAYOUT_WHERE_PKS_IN = "SELECT layout FROM Layout layout WHERE plid IN (";
9144            private static final String _SQL_SELECT_LAYOUT_WHERE = "SELECT layout FROM Layout layout WHERE ";
9145            private static final String _SQL_COUNT_LAYOUT = "SELECT COUNT(layout) FROM Layout layout";
9146            private static final String _SQL_COUNT_LAYOUT_WHERE = "SELECT COUNT(layout) FROM Layout layout WHERE ";
9147            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "layout.plid";
9148            private static final String _FILTER_SQL_SELECT_LAYOUT_WHERE = "SELECT DISTINCT {layout.*} FROM Layout layout WHERE ";
9149            private static final String _FILTER_SQL_SELECT_LAYOUT_NO_INLINE_DISTINCT_WHERE_1 =
9150                    "SELECT {Layout.*} FROM (SELECT DISTINCT layout.plid FROM Layout layout WHERE ";
9151            private static final String _FILTER_SQL_SELECT_LAYOUT_NO_INLINE_DISTINCT_WHERE_2 =
9152                    ") TEMP_TABLE INNER JOIN Layout ON TEMP_TABLE.plid = Layout.plid";
9153            private static final String _FILTER_SQL_COUNT_LAYOUT_WHERE = "SELECT COUNT(DISTINCT layout.plid) AS COUNT_VALUE FROM Layout layout WHERE ";
9154            private static final String _FILTER_ENTITY_ALIAS = "layout";
9155            private static final String _FILTER_ENTITY_TABLE = "Layout";
9156            private static final String _ORDER_BY_ENTITY_ALIAS = "layout.";
9157            private static final String _ORDER_BY_ENTITY_TABLE = "Layout.";
9158            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Layout exists with the primary key ";
9159            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Layout exists with the key {";
9160            private static final Log _log = LogFactoryUtil.getLog(LayoutPersistenceImpl.class);
9161            private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
9162                                    "uuid", "type", "hidden"
9163                            });
9164            private static final Layout _nullLayout = new LayoutImpl() {
9165                            @Override
9166                            public Object clone() {
9167                                    return this;
9168                            }
9169    
9170                            @Override
9171                            public CacheModel<Layout> toCacheModel() {
9172                                    return _nullLayoutCacheModel;
9173                            }
9174                    };
9175    
9176            private static final CacheModel<Layout> _nullLayoutCacheModel = new NullCacheModel();
9177    
9178            private static class NullCacheModel implements CacheModel<Layout>,
9179                    MVCCModel {
9180                    @Override
9181                    public long getMvccVersion() {
9182                            return -1;
9183                    }
9184    
9185                    @Override
9186                    public void setMvccVersion(long mvccVersion) {
9187                    }
9188    
9189                    @Override
9190                    public Layout toEntityModel() {
9191                            return _nullLayout;
9192                    }
9193            }
9194    }