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