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