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