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