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