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