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