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