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