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