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