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