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