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