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