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