001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.service.persistence;
016    
017    import com.liferay.portal.NoSuchLayoutException;
018    import com.liferay.portal.NoSuchModelException;
019    import com.liferay.portal.kernel.annotation.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.Layout;
041    import com.liferay.portal.model.ModelListener;
042    import com.liferay.portal.model.impl.LayoutImpl;
043    import com.liferay.portal.model.impl.LayoutModelImpl;
044    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
045    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
046    
047    import com.liferay.portlet.documentlibrary.service.persistence.DLFolderPersistence;
048    import com.liferay.portlet.expando.service.persistence.ExpandoValuePersistence;
049    import com.liferay.portlet.journal.service.persistence.JournalContentSearchPersistence;
050    import com.liferay.portlet.messageboards.service.persistence.MBMessagePersistence;
051    import com.liferay.portlet.ratings.service.persistence.RatingsStatsPersistence;
052    import com.liferay.portlet.tasks.service.persistence.TasksProposalPersistence;
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     * 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.
065     * </p>
066     *
067     * <p>
068     * Caching information and settings can be found in <code>portal.properties</code>
069     * </p>
070     *
071     * @author Brian Wing Shun Chan
072     * @see LayoutPersistence
073     * @see LayoutUtil
074     * @generated
075     */
076    public class LayoutPersistenceImpl extends BasePersistenceImpl<Layout>
077            implements LayoutPersistence {
078            public static final String FINDER_CLASS_NAME_ENTITY = LayoutImpl.class.getName();
079            public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
080                    ".List";
081            public static final FinderPath FINDER_PATH_FIND_BY_UUID = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
082                            LayoutModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
083                            "findByUuid",
084                            new String[] {
085                                    String.class.getName(),
086                                    
087                            "java.lang.Integer", "java.lang.Integer",
088                                    "com.liferay.portal.kernel.util.OrderByComparator"
089                            });
090            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
091                            LayoutModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
092                            "countByUuid", new String[] { String.class.getName() });
093            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
094                            LayoutModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
095                            "fetchByUUID_G",
096                            new String[] { String.class.getName(), Long.class.getName() });
097            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
098                            LayoutModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
099                            "countByUUID_G",
100                            new String[] { String.class.getName(), Long.class.getName() });
101            public static final FinderPath FINDER_PATH_FIND_BY_GROUPID = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
102                            LayoutModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
103                            "findByGroupId",
104                            new String[] {
105                                    Long.class.getName(),
106                                    
107                            "java.lang.Integer", "java.lang.Integer",
108                                    "com.liferay.portal.kernel.util.OrderByComparator"
109                            });
110            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
111                            LayoutModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
112                            "countByGroupId", new String[] { Long.class.getName() });
113            public static final FinderPath FINDER_PATH_FIND_BY_COMPANYID = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
114                            LayoutModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
115                            "findByCompanyId",
116                            new String[] {
117                                    Long.class.getName(),
118                                    
119                            "java.lang.Integer", "java.lang.Integer",
120                                    "com.liferay.portal.kernel.util.OrderByComparator"
121                            });
122            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
123                            LayoutModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
124                            "countByCompanyId", new String[] { Long.class.getName() });
125            public static final FinderPath FINDER_PATH_FETCH_BY_DLFOLDERID = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
126                            LayoutModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
127                            "fetchByDLFolderId", new String[] { Long.class.getName() });
128            public static final FinderPath FINDER_PATH_COUNT_BY_DLFOLDERID = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
129                            LayoutModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
130                            "countByDLFolderId", new String[] { Long.class.getName() });
131            public static final FinderPath FINDER_PATH_FETCH_BY_ICONIMAGEID = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
132                            LayoutModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
133                            "fetchByIconImageId", new String[] { Long.class.getName() });
134            public static final FinderPath FINDER_PATH_COUNT_BY_ICONIMAGEID = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
135                            LayoutModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
136                            "countByIconImageId", new String[] { Long.class.getName() });
137            public static final FinderPath FINDER_PATH_FIND_BY_G_P = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
138                            LayoutModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
139                            "findByG_P",
140                            new String[] {
141                                    Long.class.getName(), Boolean.class.getName(),
142                                    
143                            "java.lang.Integer", "java.lang.Integer",
144                                    "com.liferay.portal.kernel.util.OrderByComparator"
145                            });
146            public static final FinderPath FINDER_PATH_COUNT_BY_G_P = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
147                            LayoutModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
148                            "countByG_P",
149                            new String[] { Long.class.getName(), Boolean.class.getName() });
150            public static final FinderPath FINDER_PATH_FETCH_BY_G_P_L = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
151                            LayoutModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
152                            "fetchByG_P_L",
153                            new String[] {
154                                    Long.class.getName(), Boolean.class.getName(),
155                                    Long.class.getName()
156                            });
157            public static final FinderPath FINDER_PATH_COUNT_BY_G_P_L = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
158                            LayoutModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
159                            "countByG_P_L",
160                            new String[] {
161                                    Long.class.getName(), Boolean.class.getName(),
162                                    Long.class.getName()
163                            });
164            public static final FinderPath FINDER_PATH_FIND_BY_G_P_P = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
165                            LayoutModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
166                            "findByG_P_P",
167                            new String[] {
168                                    Long.class.getName(), Boolean.class.getName(),
169                                    Long.class.getName(),
170                                    
171                            "java.lang.Integer", "java.lang.Integer",
172                                    "com.liferay.portal.kernel.util.OrderByComparator"
173                            });
174            public static final FinderPath FINDER_PATH_COUNT_BY_G_P_P = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
175                            LayoutModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
176                            "countByG_P_P",
177                            new String[] {
178                                    Long.class.getName(), Boolean.class.getName(),
179                                    Long.class.getName()
180                            });
181            public static final FinderPath FINDER_PATH_FETCH_BY_G_P_F = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
182                            LayoutModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
183                            "fetchByG_P_F",
184                            new String[] {
185                                    Long.class.getName(), Boolean.class.getName(),
186                                    String.class.getName()
187                            });
188            public static final FinderPath FINDER_PATH_COUNT_BY_G_P_F = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
189                            LayoutModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
190                            "countByG_P_F",
191                            new String[] {
192                                    Long.class.getName(), Boolean.class.getName(),
193                                    String.class.getName()
194                            });
195            public static final FinderPath FINDER_PATH_FIND_BY_G_P_T = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
196                            LayoutModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
197                            "findByG_P_T",
198                            new String[] {
199                                    Long.class.getName(), Boolean.class.getName(),
200                                    String.class.getName(),
201                                    
202                            "java.lang.Integer", "java.lang.Integer",
203                                    "com.liferay.portal.kernel.util.OrderByComparator"
204                            });
205            public static final FinderPath FINDER_PATH_COUNT_BY_G_P_T = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
206                            LayoutModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
207                            "countByG_P_T",
208                            new String[] {
209                                    Long.class.getName(), Boolean.class.getName(),
210                                    String.class.getName()
211                            });
212            public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
213                            LayoutModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
214                            "findAll", new String[0]);
215            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
216                            LayoutModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
217                            "countAll", new String[0]);
218    
219            /**
220             * Caches the layout in the entity cache if it is enabled.
221             *
222             * @param layout the layout to cache
223             */
224            public void cacheResult(Layout layout) {
225                    EntityCacheUtil.putResult(LayoutModelImpl.ENTITY_CACHE_ENABLED,
226                            LayoutImpl.class, layout.getPrimaryKey(), layout);
227    
228                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
229                            new Object[] { layout.getUuid(), new Long(layout.getGroupId()) },
230                            layout);
231    
232                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_DLFOLDERID,
233                            new Object[] { new Long(layout.getDlFolderId()) }, layout);
234    
235                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_ICONIMAGEID,
236                            new Object[] { new Long(layout.getIconImageId()) }, layout);
237    
238                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_L,
239                            new Object[] {
240                                    new Long(layout.getGroupId()),
241                                    Boolean.valueOf(layout.getPrivateLayout()),
242                                    new Long(layout.getLayoutId())
243                            }, layout);
244    
245                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_F,
246                            new Object[] {
247                                    new Long(layout.getGroupId()),
248                                    Boolean.valueOf(layout.getPrivateLayout()),
249                                    
250                            layout.getFriendlyURL()
251                            }, layout);
252            }
253    
254            /**
255             * Caches the layouts in the entity cache if it is enabled.
256             *
257             * @param layouts the layouts to cache
258             */
259            public void cacheResult(List<Layout> layouts) {
260                    for (Layout layout : layouts) {
261                            if (EntityCacheUtil.getResult(
262                                                    LayoutModelImpl.ENTITY_CACHE_ENABLED, LayoutImpl.class,
263                                                    layout.getPrimaryKey(), this) == null) {
264                                    cacheResult(layout);
265                            }
266                    }
267            }
268    
269            /**
270             * Clears the cache for all layouts.
271             *
272             * <p>
273             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
274             * </p>
275             */
276            public void clearCache() {
277                    CacheRegistryUtil.clear(LayoutImpl.class.getName());
278                    EntityCacheUtil.clearCache(LayoutImpl.class.getName());
279                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
280                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
281            }
282    
283            /**
284             * Clears the cache for the layout.
285             *
286             * <p>
287             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
288             * </p>
289             */
290            public void clearCache(Layout layout) {
291                    EntityCacheUtil.removeResult(LayoutModelImpl.ENTITY_CACHE_ENABLED,
292                            LayoutImpl.class, layout.getPrimaryKey());
293    
294                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
295                            new Object[] { layout.getUuid(), new Long(layout.getGroupId()) });
296    
297                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_DLFOLDERID,
298                            new Object[] { new Long(layout.getDlFolderId()) });
299    
300                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_ICONIMAGEID,
301                            new Object[] { new Long(layout.getIconImageId()) });
302    
303                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P_L,
304                            new Object[] {
305                                    new Long(layout.getGroupId()),
306                                    Boolean.valueOf(layout.getPrivateLayout()),
307                                    new Long(layout.getLayoutId())
308                            });
309    
310                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P_F,
311                            new Object[] {
312                                    new Long(layout.getGroupId()),
313                                    Boolean.valueOf(layout.getPrivateLayout()),
314                                    
315                            layout.getFriendlyURL()
316                            });
317            }
318    
319            /**
320             * Creates a new layout with the primary key. Does not add the layout to the database.
321             *
322             * @param plid the primary key for the new layout
323             * @return the new layout
324             */
325            public Layout create(long plid) {
326                    Layout layout = new LayoutImpl();
327    
328                    layout.setNew(true);
329                    layout.setPrimaryKey(plid);
330    
331                    String uuid = PortalUUIDUtil.generate();
332    
333                    layout.setUuid(uuid);
334    
335                    return layout;
336            }
337    
338            /**
339             * Removes the layout with the primary key from the database. Also notifies the appropriate model listeners.
340             *
341             * @param primaryKey the primary key of the layout to remove
342             * @return the layout that was removed
343             * @throws com.liferay.portal.NoSuchModelException if a layout with the primary key could not be found
344             * @throws SystemException if a system exception occurred
345             */
346            public Layout remove(Serializable primaryKey)
347                    throws NoSuchModelException, SystemException {
348                    return remove(((Long)primaryKey).longValue());
349            }
350    
351            /**
352             * Removes the layout with the primary key from the database. Also notifies the appropriate model listeners.
353             *
354             * @param plid the primary key of the layout to remove
355             * @return the layout that was removed
356             * @throws com.liferay.portal.NoSuchLayoutException if a layout with the primary key could not be found
357             * @throws SystemException if a system exception occurred
358             */
359            public Layout remove(long plid)
360                    throws NoSuchLayoutException, SystemException {
361                    Session session = null;
362    
363                    try {
364                            session = openSession();
365    
366                            Layout layout = (Layout)session.get(LayoutImpl.class, new Long(plid));
367    
368                            if (layout == null) {
369                                    if (_log.isWarnEnabled()) {
370                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + plid);
371                                    }
372    
373                                    throw new NoSuchLayoutException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
374                                            plid);
375                            }
376    
377                            return remove(layout);
378                    }
379                    catch (NoSuchLayoutException nsee) {
380                            throw nsee;
381                    }
382                    catch (Exception e) {
383                            throw processException(e);
384                    }
385                    finally {
386                            closeSession(session);
387                    }
388            }
389    
390            protected Layout removeImpl(Layout layout) throws SystemException {
391                    layout = toUnwrappedModel(layout);
392    
393                    Session session = null;
394    
395                    try {
396                            session = openSession();
397    
398                            BatchSessionUtil.delete(session, layout);
399                    }
400                    catch (Exception e) {
401                            throw processException(e);
402                    }
403                    finally {
404                            closeSession(session);
405                    }
406    
407                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
408    
409                    LayoutModelImpl layoutModelImpl = (LayoutModelImpl)layout;
410    
411                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
412                            new Object[] {
413                                    layoutModelImpl.getUuid(),
414                                    new Long(layoutModelImpl.getGroupId())
415                            });
416    
417                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_DLFOLDERID,
418                            new Object[] { new Long(layoutModelImpl.getDlFolderId()) });
419    
420                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_ICONIMAGEID,
421                            new Object[] { new Long(layoutModelImpl.getIconImageId()) });
422    
423                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P_L,
424                            new Object[] {
425                                    new Long(layoutModelImpl.getGroupId()),
426                                    Boolean.valueOf(layoutModelImpl.getPrivateLayout()),
427                                    new Long(layoutModelImpl.getLayoutId())
428                            });
429    
430                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P_F,
431                            new Object[] {
432                                    new Long(layoutModelImpl.getGroupId()),
433                                    Boolean.valueOf(layoutModelImpl.getPrivateLayout()),
434                                    
435                            layoutModelImpl.getFriendlyURL()
436                            });
437    
438                    EntityCacheUtil.removeResult(LayoutModelImpl.ENTITY_CACHE_ENABLED,
439                            LayoutImpl.class, layout.getPrimaryKey());
440    
441                    return layout;
442            }
443    
444            public Layout updateImpl(com.liferay.portal.model.Layout layout,
445                    boolean merge) throws SystemException {
446                    layout = toUnwrappedModel(layout);
447    
448                    boolean isNew = layout.isNew();
449    
450                    LayoutModelImpl layoutModelImpl = (LayoutModelImpl)layout;
451    
452                    if (Validator.isNull(layout.getUuid())) {
453                            String uuid = PortalUUIDUtil.generate();
454    
455                            layout.setUuid(uuid);
456                    }
457    
458                    Session session = null;
459    
460                    try {
461                            session = openSession();
462    
463                            BatchSessionUtil.update(session, layout, merge);
464    
465                            layout.setNew(false);
466                    }
467                    catch (Exception e) {
468                            throw processException(e);
469                    }
470                    finally {
471                            closeSession(session);
472                    }
473    
474                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
475    
476                    EntityCacheUtil.putResult(LayoutModelImpl.ENTITY_CACHE_ENABLED,
477                            LayoutImpl.class, layout.getPrimaryKey(), layout);
478    
479                    if (!isNew &&
480                                    (!Validator.equals(layout.getUuid(),
481                                            layoutModelImpl.getOriginalUuid()) ||
482                                    (layout.getGroupId() != layoutModelImpl.getOriginalGroupId()))) {
483                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
484                                    new Object[] {
485                                            layoutModelImpl.getOriginalUuid(),
486                                            new Long(layoutModelImpl.getOriginalGroupId())
487                                    });
488                    }
489    
490                    if (isNew ||
491                                    (!Validator.equals(layout.getUuid(),
492                                            layoutModelImpl.getOriginalUuid()) ||
493                                    (layout.getGroupId() != layoutModelImpl.getOriginalGroupId()))) {
494                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
495                                    new Object[] { layout.getUuid(), new Long(layout.getGroupId()) },
496                                    layout);
497                    }
498    
499                    if (!isNew &&
500                                    (layout.getDlFolderId() != layoutModelImpl.getOriginalDlFolderId())) {
501                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_DLFOLDERID,
502                                    new Object[] { new Long(layoutModelImpl.getOriginalDlFolderId()) });
503                    }
504    
505                    if (isNew ||
506                                    (layout.getDlFolderId() != layoutModelImpl.getOriginalDlFolderId())) {
507                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_DLFOLDERID,
508                                    new Object[] { new Long(layout.getDlFolderId()) }, layout);
509                    }
510    
511                    if (!isNew &&
512                                    (layout.getIconImageId() != layoutModelImpl.getOriginalIconImageId())) {
513                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_ICONIMAGEID,
514                                    new Object[] { new Long(layoutModelImpl.getOriginalIconImageId()) });
515                    }
516    
517                    if (isNew ||
518                                    (layout.getIconImageId() != layoutModelImpl.getOriginalIconImageId())) {
519                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_ICONIMAGEID,
520                                    new Object[] { new Long(layout.getIconImageId()) }, layout);
521                    }
522    
523                    if (!isNew &&
524                                    ((layout.getGroupId() != layoutModelImpl.getOriginalGroupId()) ||
525                                    (layout.getPrivateLayout() != layoutModelImpl.getOriginalPrivateLayout()) ||
526                                    (layout.getLayoutId() != layoutModelImpl.getOriginalLayoutId()))) {
527                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P_L,
528                                    new Object[] {
529                                            new Long(layoutModelImpl.getOriginalGroupId()),
530                                            Boolean.valueOf(layoutModelImpl.getOriginalPrivateLayout()),
531                                            new Long(layoutModelImpl.getOriginalLayoutId())
532                                    });
533                    }
534    
535                    if (isNew ||
536                                    ((layout.getGroupId() != layoutModelImpl.getOriginalGroupId()) ||
537                                    (layout.getPrivateLayout() != layoutModelImpl.getOriginalPrivateLayout()) ||
538                                    (layout.getLayoutId() != layoutModelImpl.getOriginalLayoutId()))) {
539                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_L,
540                                    new Object[] {
541                                            new Long(layout.getGroupId()),
542                                            Boolean.valueOf(layout.getPrivateLayout()),
543                                            new Long(layout.getLayoutId())
544                                    }, layout);
545                    }
546    
547                    if (!isNew &&
548                                    ((layout.getGroupId() != layoutModelImpl.getOriginalGroupId()) ||
549                                    (layout.getPrivateLayout() != layoutModelImpl.getOriginalPrivateLayout()) ||
550                                    !Validator.equals(layout.getFriendlyURL(),
551                                            layoutModelImpl.getOriginalFriendlyURL()))) {
552                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P_F,
553                                    new Object[] {
554                                            new Long(layoutModelImpl.getOriginalGroupId()),
555                                            Boolean.valueOf(layoutModelImpl.getOriginalPrivateLayout()),
556                                            
557                                    layoutModelImpl.getOriginalFriendlyURL()
558                                    });
559                    }
560    
561                    if (isNew ||
562                                    ((layout.getGroupId() != layoutModelImpl.getOriginalGroupId()) ||
563                                    (layout.getPrivateLayout() != layoutModelImpl.getOriginalPrivateLayout()) ||
564                                    !Validator.equals(layout.getFriendlyURL(),
565                                            layoutModelImpl.getOriginalFriendlyURL()))) {
566                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_F,
567                                    new Object[] {
568                                            new Long(layout.getGroupId()),
569                                            Boolean.valueOf(layout.getPrivateLayout()),
570                                            
571                                    layout.getFriendlyURL()
572                                    }, layout);
573                    }
574    
575                    return layout;
576            }
577    
578            protected Layout toUnwrappedModel(Layout layout) {
579                    if (layout instanceof LayoutImpl) {
580                            return layout;
581                    }
582    
583                    LayoutImpl layoutImpl = new LayoutImpl();
584    
585                    layoutImpl.setNew(layout.isNew());
586                    layoutImpl.setPrimaryKey(layout.getPrimaryKey());
587    
588                    layoutImpl.setUuid(layout.getUuid());
589                    layoutImpl.setPlid(layout.getPlid());
590                    layoutImpl.setGroupId(layout.getGroupId());
591                    layoutImpl.setCompanyId(layout.getCompanyId());
592                    layoutImpl.setPrivateLayout(layout.isPrivateLayout());
593                    layoutImpl.setLayoutId(layout.getLayoutId());
594                    layoutImpl.setParentLayoutId(layout.getParentLayoutId());
595                    layoutImpl.setName(layout.getName());
596                    layoutImpl.setTitle(layout.getTitle());
597                    layoutImpl.setDescription(layout.getDescription());
598                    layoutImpl.setType(layout.getType());
599                    layoutImpl.setTypeSettings(layout.getTypeSettings());
600                    layoutImpl.setHidden(layout.isHidden());
601                    layoutImpl.setFriendlyURL(layout.getFriendlyURL());
602                    layoutImpl.setIconImage(layout.isIconImage());
603                    layoutImpl.setIconImageId(layout.getIconImageId());
604                    layoutImpl.setThemeId(layout.getThemeId());
605                    layoutImpl.setColorSchemeId(layout.getColorSchemeId());
606                    layoutImpl.setWapThemeId(layout.getWapThemeId());
607                    layoutImpl.setWapColorSchemeId(layout.getWapColorSchemeId());
608                    layoutImpl.setCss(layout.getCss());
609                    layoutImpl.setPriority(layout.getPriority());
610                    layoutImpl.setLayoutPrototypeId(layout.getLayoutPrototypeId());
611                    layoutImpl.setDlFolderId(layout.getDlFolderId());
612    
613                    return layoutImpl;
614            }
615    
616            /**
617             * Finds the layout with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
618             *
619             * @param primaryKey the primary key of the layout to find
620             * @return the layout
621             * @throws com.liferay.portal.NoSuchModelException if a layout with the primary key could not be found
622             * @throws SystemException if a system exception occurred
623             */
624            public Layout findByPrimaryKey(Serializable primaryKey)
625                    throws NoSuchModelException, SystemException {
626                    return findByPrimaryKey(((Long)primaryKey).longValue());
627            }
628    
629            /**
630             * Finds the layout with the primary key or throws a {@link com.liferay.portal.NoSuchLayoutException} if it could not be found.
631             *
632             * @param plid the primary key of the layout to find
633             * @return the layout
634             * @throws com.liferay.portal.NoSuchLayoutException if a layout with the primary key could not be found
635             * @throws SystemException if a system exception occurred
636             */
637            public Layout findByPrimaryKey(long plid)
638                    throws NoSuchLayoutException, SystemException {
639                    Layout layout = fetchByPrimaryKey(plid);
640    
641                    if (layout == null) {
642                            if (_log.isWarnEnabled()) {
643                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + plid);
644                            }
645    
646                            throw new NoSuchLayoutException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
647                                    plid);
648                    }
649    
650                    return layout;
651            }
652    
653            /**
654             * Finds the layout with the primary key or returns <code>null</code> if it could not be found.
655             *
656             * @param primaryKey the primary key of the layout to find
657             * @return the layout, or <code>null</code> if a layout with the primary key could not be found
658             * @throws SystemException if a system exception occurred
659             */
660            public Layout fetchByPrimaryKey(Serializable primaryKey)
661                    throws SystemException {
662                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
663            }
664    
665            /**
666             * Finds the layout with the primary key or returns <code>null</code> if it could not be found.
667             *
668             * @param plid the primary key of the layout to find
669             * @return the layout, or <code>null</code> if a layout with the primary key could not be found
670             * @throws SystemException if a system exception occurred
671             */
672            public Layout fetchByPrimaryKey(long plid) throws SystemException {
673                    Layout layout = (Layout)EntityCacheUtil.getResult(LayoutModelImpl.ENTITY_CACHE_ENABLED,
674                                    LayoutImpl.class, plid, this);
675    
676                    if (layout == null) {
677                            Session session = null;
678    
679                            try {
680                                    session = openSession();
681    
682                                    layout = (Layout)session.get(LayoutImpl.class, new Long(plid));
683                            }
684                            catch (Exception e) {
685                                    throw processException(e);
686                            }
687                            finally {
688                                    if (layout != null) {
689                                            cacheResult(layout);
690                                    }
691    
692                                    closeSession(session);
693                            }
694                    }
695    
696                    return layout;
697            }
698    
699            /**
700             * Finds all the layouts where uuid = &#63;.
701             *
702             * @param uuid the uuid to search with
703             * @return the matching layouts
704             * @throws SystemException if a system exception occurred
705             */
706            public List<Layout> findByUuid(String uuid) throws SystemException {
707                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
708            }
709    
710            /**
711             * Finds a range of all the layouts where uuid = &#63;.
712             *
713             * <p>
714             * 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.
715             * </p>
716             *
717             * @param uuid the uuid to search with
718             * @param start the lower bound of the range of layouts to return
719             * @param end the upper bound of the range of layouts to return (not inclusive)
720             * @return the range of matching layouts
721             * @throws SystemException if a system exception occurred
722             */
723            public List<Layout> findByUuid(String uuid, int start, int end)
724                    throws SystemException {
725                    return findByUuid(uuid, start, end, null);
726            }
727    
728            /**
729             * Finds an ordered range of all the layouts where uuid = &#63;.
730             *
731             * <p>
732             * 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.
733             * </p>
734             *
735             * @param uuid the uuid to search with
736             * @param start the lower bound of the range of layouts to return
737             * @param end the upper bound of the range of layouts to return (not inclusive)
738             * @param orderByComparator the comparator to order the results by
739             * @return the ordered range of matching layouts
740             * @throws SystemException if a system exception occurred
741             */
742            public List<Layout> findByUuid(String uuid, int start, int end,
743                    OrderByComparator orderByComparator) throws SystemException {
744                    Object[] finderArgs = new Object[] {
745                                    uuid,
746                                    
747                                    String.valueOf(start), String.valueOf(end),
748                                    String.valueOf(orderByComparator)
749                            };
750    
751                    List<Layout> list = (List<Layout>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_UUID,
752                                    finderArgs, this);
753    
754                    if (list == null) {
755                            StringBundler query = null;
756    
757                            if (orderByComparator != null) {
758                                    query = new StringBundler(3 +
759                                                    (orderByComparator.getOrderByFields().length * 3));
760                            }
761                            else {
762                                    query = new StringBundler(3);
763                            }
764    
765                            query.append(_SQL_SELECT_LAYOUT_WHERE);
766    
767                            if (uuid == null) {
768                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
769                            }
770                            else {
771                                    if (uuid.equals(StringPool.BLANK)) {
772                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
773                                    }
774                                    else {
775                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
776                                    }
777                            }
778    
779                            if (orderByComparator != null) {
780                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
781                                            orderByComparator);
782                            }
783    
784                            else {
785                                    query.append(LayoutModelImpl.ORDER_BY_JPQL);
786                            }
787    
788                            String sql = query.toString();
789    
790                            Session session = null;
791    
792                            try {
793                                    session = openSession();
794    
795                                    Query q = session.createQuery(sql);
796    
797                                    QueryPos qPos = QueryPos.getInstance(q);
798    
799                                    if (uuid != null) {
800                                            qPos.add(uuid);
801                                    }
802    
803                                    list = (List<Layout>)QueryUtil.list(q, getDialect(), start, end);
804                            }
805                            catch (Exception e) {
806                                    throw processException(e);
807                            }
808                            finally {
809                                    if (list == null) {
810                                            FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_UUID,
811                                                    finderArgs);
812                                    }
813                                    else {
814                                            cacheResult(list);
815    
816                                            FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_UUID,
817                                                    finderArgs, list);
818                                    }
819    
820                                    closeSession(session);
821                            }
822                    }
823    
824                    return list;
825            }
826    
827            /**
828             * Finds the first layout in the ordered set where uuid = &#63;.
829             *
830             * <p>
831             * 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.
832             * </p>
833             *
834             * @param uuid the uuid to search with
835             * @param orderByComparator the comparator to order the set by
836             * @return the first matching layout
837             * @throws com.liferay.portal.NoSuchLayoutException if a matching layout could not be found
838             * @throws SystemException if a system exception occurred
839             */
840            public Layout findByUuid_First(String uuid,
841                    OrderByComparator orderByComparator)
842                    throws NoSuchLayoutException, SystemException {
843                    List<Layout> list = findByUuid(uuid, 0, 1, orderByComparator);
844    
845                    if (list.isEmpty()) {
846                            StringBundler msg = new StringBundler(4);
847    
848                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
849    
850                            msg.append("uuid=");
851                            msg.append(uuid);
852    
853                            msg.append(StringPool.CLOSE_CURLY_BRACE);
854    
855                            throw new NoSuchLayoutException(msg.toString());
856                    }
857                    else {
858                            return list.get(0);
859                    }
860            }
861    
862            /**
863             * Finds the last layout in the ordered set where uuid = &#63;.
864             *
865             * <p>
866             * 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.
867             * </p>
868             *
869             * @param uuid the uuid to search with
870             * @param orderByComparator the comparator to order the set by
871             * @return the last matching layout
872             * @throws com.liferay.portal.NoSuchLayoutException if a matching layout could not be found
873             * @throws SystemException if a system exception occurred
874             */
875            public Layout findByUuid_Last(String uuid,
876                    OrderByComparator orderByComparator)
877                    throws NoSuchLayoutException, SystemException {
878                    int count = countByUuid(uuid);
879    
880                    List<Layout> list = findByUuid(uuid, count - 1, count, orderByComparator);
881    
882                    if (list.isEmpty()) {
883                            StringBundler msg = new StringBundler(4);
884    
885                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
886    
887                            msg.append("uuid=");
888                            msg.append(uuid);
889    
890                            msg.append(StringPool.CLOSE_CURLY_BRACE);
891    
892                            throw new NoSuchLayoutException(msg.toString());
893                    }
894                    else {
895                            return list.get(0);
896                    }
897            }
898    
899            /**
900             * Finds the layouts before and after the current layout in the ordered set where uuid = &#63;.
901             *
902             * <p>
903             * 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.
904             * </p>
905             *
906             * @param plid the primary key of the current layout
907             * @param uuid the uuid to search with
908             * @param orderByComparator the comparator to order the set by
909             * @return the previous, current, and next layout
910             * @throws com.liferay.portal.NoSuchLayoutException if a layout with the primary key could not be found
911             * @throws SystemException if a system exception occurred
912             */
913            public Layout[] findByUuid_PrevAndNext(long plid, String uuid,
914                    OrderByComparator orderByComparator)
915                    throws NoSuchLayoutException, SystemException {
916                    Layout layout = findByPrimaryKey(plid);
917    
918                    Session session = null;
919    
920                    try {
921                            session = openSession();
922    
923                            Layout[] array = new LayoutImpl[3];
924    
925                            array[0] = getByUuid_PrevAndNext(session, layout, uuid,
926                                            orderByComparator, true);
927    
928                            array[1] = layout;
929    
930                            array[2] = getByUuid_PrevAndNext(session, layout, uuid,
931                                            orderByComparator, false);
932    
933                            return array;
934                    }
935                    catch (Exception e) {
936                            throw processException(e);
937                    }
938                    finally {
939                            closeSession(session);
940                    }
941            }
942    
943            protected Layout getByUuid_PrevAndNext(Session session, Layout layout,
944                    String uuid, OrderByComparator orderByComparator, boolean previous) {
945                    StringBundler query = null;
946    
947                    if (orderByComparator != null) {
948                            query = new StringBundler(6 +
949                                            (orderByComparator.getOrderByFields().length * 6));
950                    }
951                    else {
952                            query = new StringBundler(3);
953                    }
954    
955                    query.append(_SQL_SELECT_LAYOUT_WHERE);
956    
957                    if (uuid == null) {
958                            query.append(_FINDER_COLUMN_UUID_UUID_1);
959                    }
960                    else {
961                            if (uuid.equals(StringPool.BLANK)) {
962                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
963                            }
964                            else {
965                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
966                            }
967                    }
968    
969                    if (orderByComparator != null) {
970                            String[] orderByFields = orderByComparator.getOrderByFields();
971    
972                            if (orderByFields.length > 0) {
973                                    query.append(WHERE_AND);
974                            }
975    
976                            for (int i = 0; i < orderByFields.length; i++) {
977                                    query.append(_ORDER_BY_ENTITY_ALIAS);
978                                    query.append(orderByFields[i]);
979    
980                                    if ((i + 1) < orderByFields.length) {
981                                            if (orderByComparator.isAscending() ^ previous) {
982                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
983                                            }
984                                            else {
985                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
986                                            }
987                                    }
988                                    else {
989                                            if (orderByComparator.isAscending() ^ previous) {
990                                                    query.append(WHERE_GREATER_THAN);
991                                            }
992                                            else {
993                                                    query.append(WHERE_LESSER_THAN);
994                                            }
995                                    }
996                            }
997    
998                            query.append(ORDER_BY_CLAUSE);
999    
1000                            for (int i = 0; i < orderByFields.length; i++) {
1001                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1002                                    query.append(orderByFields[i]);
1003    
1004                                    if ((i + 1) < orderByFields.length) {
1005                                            if (orderByComparator.isAscending() ^ previous) {
1006                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1007                                            }
1008                                            else {
1009                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1010                                            }
1011                                    }
1012                                    else {
1013                                            if (orderByComparator.isAscending() ^ previous) {
1014                                                    query.append(ORDER_BY_ASC);
1015                                            }
1016                                            else {
1017                                                    query.append(ORDER_BY_DESC);
1018                                            }
1019                                    }
1020                            }
1021                    }
1022    
1023                    else {
1024                            query.append(LayoutModelImpl.ORDER_BY_JPQL);
1025                    }
1026    
1027                    String sql = query.toString();
1028    
1029                    Query q = session.createQuery(sql);
1030    
1031                    q.setFirstResult(0);
1032                    q.setMaxResults(2);
1033    
1034                    QueryPos qPos = QueryPos.getInstance(q);
1035    
1036                    if (uuid != null) {
1037                            qPos.add(uuid);
1038                    }
1039    
1040                    if (orderByComparator != null) {
1041                            Object[] values = orderByComparator.getOrderByValues(layout);
1042    
1043                            for (Object value : values) {
1044                                    qPos.add(value);
1045                            }
1046                    }
1047    
1048                    List<Layout> list = q.list();
1049    
1050                    if (list.size() == 2) {
1051                            return list.get(1);
1052                    }
1053                    else {
1054                            return null;
1055                    }
1056            }
1057    
1058            /**
1059             * Finds the layout where uuid = &#63; and groupId = &#63; or throws a {@link com.liferay.portal.NoSuchLayoutException} if it could not be found.
1060             *
1061             * @param uuid the uuid to search with
1062             * @param groupId the group id to search with
1063             * @return the matching layout
1064             * @throws com.liferay.portal.NoSuchLayoutException if a matching layout could not be found
1065             * @throws SystemException if a system exception occurred
1066             */
1067            public Layout findByUUID_G(String uuid, long groupId)
1068                    throws NoSuchLayoutException, SystemException {
1069                    Layout layout = fetchByUUID_G(uuid, groupId);
1070    
1071                    if (layout == null) {
1072                            StringBundler msg = new StringBundler(6);
1073    
1074                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1075    
1076                            msg.append("uuid=");
1077                            msg.append(uuid);
1078    
1079                            msg.append(", groupId=");
1080                            msg.append(groupId);
1081    
1082                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1083    
1084                            if (_log.isWarnEnabled()) {
1085                                    _log.warn(msg.toString());
1086                            }
1087    
1088                            throw new NoSuchLayoutException(msg.toString());
1089                    }
1090    
1091                    return layout;
1092            }
1093    
1094            /**
1095             * Finds the layout where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
1096             *
1097             * @param uuid the uuid to search with
1098             * @param groupId the group id to search with
1099             * @return the matching layout, or <code>null</code> if a matching layout could not be found
1100             * @throws SystemException if a system exception occurred
1101             */
1102            public Layout fetchByUUID_G(String uuid, long groupId)
1103                    throws SystemException {
1104                    return fetchByUUID_G(uuid, groupId, true);
1105            }
1106    
1107            /**
1108             * Finds the layout where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
1109             *
1110             * @param uuid the uuid to search with
1111             * @param groupId the group id to search with
1112             * @return the matching layout, or <code>null</code> if a matching layout could not be found
1113             * @throws SystemException if a system exception occurred
1114             */
1115            public Layout fetchByUUID_G(String uuid, long groupId,
1116                    boolean retrieveFromCache) throws SystemException {
1117                    Object[] finderArgs = new Object[] { uuid, groupId };
1118    
1119                    Object result = null;
1120    
1121                    if (retrieveFromCache) {
1122                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
1123                                            finderArgs, this);
1124                    }
1125    
1126                    if (result == null) {
1127                            StringBundler query = new StringBundler(4);
1128    
1129                            query.append(_SQL_SELECT_LAYOUT_WHERE);
1130    
1131                            if (uuid == null) {
1132                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
1133                            }
1134                            else {
1135                                    if (uuid.equals(StringPool.BLANK)) {
1136                                            query.append(_FINDER_COLUMN_UUID_G_UUID_3);
1137                                    }
1138                                    else {
1139                                            query.append(_FINDER_COLUMN_UUID_G_UUID_2);
1140                                    }
1141                            }
1142    
1143                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
1144    
1145                            query.append(LayoutModelImpl.ORDER_BY_JPQL);
1146    
1147                            String sql = query.toString();
1148    
1149                            Session session = null;
1150    
1151                            try {
1152                                    session = openSession();
1153    
1154                                    Query q = session.createQuery(sql);
1155    
1156                                    QueryPos qPos = QueryPos.getInstance(q);
1157    
1158                                    if (uuid != null) {
1159                                            qPos.add(uuid);
1160                                    }
1161    
1162                                    qPos.add(groupId);
1163    
1164                                    List<Layout> list = q.list();
1165    
1166                                    result = list;
1167    
1168                                    Layout layout = null;
1169    
1170                                    if (list.isEmpty()) {
1171                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1172                                                    finderArgs, list);
1173                                    }
1174                                    else {
1175                                            layout = list.get(0);
1176    
1177                                            cacheResult(layout);
1178    
1179                                            if ((layout.getUuid() == null) ||
1180                                                            !layout.getUuid().equals(uuid) ||
1181                                                            (layout.getGroupId() != groupId)) {
1182                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1183                                                            finderArgs, layout);
1184                                            }
1185                                    }
1186    
1187                                    return layout;
1188                            }
1189                            catch (Exception e) {
1190                                    throw processException(e);
1191                            }
1192                            finally {
1193                                    if (result == null) {
1194                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
1195                                                    finderArgs);
1196                                    }
1197    
1198                                    closeSession(session);
1199                            }
1200                    }
1201                    else {
1202                            if (result instanceof List<?>) {
1203                                    return null;
1204                            }
1205                            else {
1206                                    return (Layout)result;
1207                            }
1208                    }
1209            }
1210    
1211            /**
1212             * Finds all the layouts where groupId = &#63;.
1213             *
1214             * @param groupId the group id to search with
1215             * @return the matching layouts
1216             * @throws SystemException if a system exception occurred
1217             */
1218            public List<Layout> findByGroupId(long groupId) throws SystemException {
1219                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1220            }
1221    
1222            /**
1223             * Finds a range of all the layouts where groupId = &#63;.
1224             *
1225             * <p>
1226             * 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.
1227             * </p>
1228             *
1229             * @param groupId the group id to search with
1230             * @param start the lower bound of the range of layouts to return
1231             * @param end the upper bound of the range of layouts to return (not inclusive)
1232             * @return the range of matching layouts
1233             * @throws SystemException if a system exception occurred
1234             */
1235            public List<Layout> findByGroupId(long groupId, int start, int end)
1236                    throws SystemException {
1237                    return findByGroupId(groupId, start, end, null);
1238            }
1239    
1240            /**
1241             * Finds an ordered range of all the layouts where groupId = &#63;.
1242             *
1243             * <p>
1244             * 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.
1245             * </p>
1246             *
1247             * @param groupId the group id to search with
1248             * @param start the lower bound of the range of layouts to return
1249             * @param end the upper bound of the range of layouts to return (not inclusive)
1250             * @param orderByComparator the comparator to order the results by
1251             * @return the ordered range of matching layouts
1252             * @throws SystemException if a system exception occurred
1253             */
1254            public List<Layout> findByGroupId(long groupId, int start, int end,
1255                    OrderByComparator orderByComparator) throws SystemException {
1256                    Object[] finderArgs = new Object[] {
1257                                    groupId,
1258                                    
1259                                    String.valueOf(start), String.valueOf(end),
1260                                    String.valueOf(orderByComparator)
1261                            };
1262    
1263                    List<Layout> list = (List<Layout>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
1264                                    finderArgs, this);
1265    
1266                    if (list == null) {
1267                            StringBundler query = null;
1268    
1269                            if (orderByComparator != null) {
1270                                    query = new StringBundler(3 +
1271                                                    (orderByComparator.getOrderByFields().length * 3));
1272                            }
1273                            else {
1274                                    query = new StringBundler(3);
1275                            }
1276    
1277                            query.append(_SQL_SELECT_LAYOUT_WHERE);
1278    
1279                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1280    
1281                            if (orderByComparator != null) {
1282                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1283                                            orderByComparator);
1284                            }
1285    
1286                            else {
1287                                    query.append(LayoutModelImpl.ORDER_BY_JPQL);
1288                            }
1289    
1290                            String sql = query.toString();
1291    
1292                            Session session = null;
1293    
1294                            try {
1295                                    session = openSession();
1296    
1297                                    Query q = session.createQuery(sql);
1298    
1299                                    QueryPos qPos = QueryPos.getInstance(q);
1300    
1301                                    qPos.add(groupId);
1302    
1303                                    list = (List<Layout>)QueryUtil.list(q, getDialect(), start, end);
1304                            }
1305                            catch (Exception e) {
1306                                    throw processException(e);
1307                            }
1308                            finally {
1309                                    if (list == null) {
1310                                            FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_GROUPID,
1311                                                    finderArgs);
1312                                    }
1313                                    else {
1314                                            cacheResult(list);
1315    
1316                                            FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
1317                                                    finderArgs, list);
1318                                    }
1319    
1320                                    closeSession(session);
1321                            }
1322                    }
1323    
1324                    return list;
1325            }
1326    
1327            /**
1328             * Finds the first layout in the ordered set where groupId = &#63;.
1329             *
1330             * <p>
1331             * 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.
1332             * </p>
1333             *
1334             * @param groupId the group id to search with
1335             * @param orderByComparator the comparator to order the set by
1336             * @return the first matching layout
1337             * @throws com.liferay.portal.NoSuchLayoutException if a matching layout could not be found
1338             * @throws SystemException if a system exception occurred
1339             */
1340            public Layout findByGroupId_First(long groupId,
1341                    OrderByComparator orderByComparator)
1342                    throws NoSuchLayoutException, SystemException {
1343                    List<Layout> list = findByGroupId(groupId, 0, 1, orderByComparator);
1344    
1345                    if (list.isEmpty()) {
1346                            StringBundler msg = new StringBundler(4);
1347    
1348                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1349    
1350                            msg.append("groupId=");
1351                            msg.append(groupId);
1352    
1353                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1354    
1355                            throw new NoSuchLayoutException(msg.toString());
1356                    }
1357                    else {
1358                            return list.get(0);
1359                    }
1360            }
1361    
1362            /**
1363             * Finds the last layout in the ordered set where groupId = &#63;.
1364             *
1365             * <p>
1366             * 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.
1367             * </p>
1368             *
1369             * @param groupId the group id to search with
1370             * @param orderByComparator the comparator to order the set by
1371             * @return the last matching layout
1372             * @throws com.liferay.portal.NoSuchLayoutException if a matching layout could not be found
1373             * @throws SystemException if a system exception occurred
1374             */
1375            public Layout findByGroupId_Last(long groupId,
1376                    OrderByComparator orderByComparator)
1377                    throws NoSuchLayoutException, SystemException {
1378                    int count = countByGroupId(groupId);
1379    
1380                    List<Layout> list = findByGroupId(groupId, count - 1, count,
1381                                    orderByComparator);
1382    
1383                    if (list.isEmpty()) {
1384                            StringBundler msg = new StringBundler(4);
1385    
1386                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1387    
1388                            msg.append("groupId=");
1389                            msg.append(groupId);
1390    
1391                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1392    
1393                            throw new NoSuchLayoutException(msg.toString());
1394                    }
1395                    else {
1396                            return list.get(0);
1397                    }
1398            }
1399    
1400            /**
1401             * Finds the layouts before and after the current layout in the ordered set where groupId = &#63;.
1402             *
1403             * <p>
1404             * 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.
1405             * </p>
1406             *
1407             * @param plid the primary key of the current layout
1408             * @param groupId the group id to search with
1409             * @param orderByComparator the comparator to order the set by
1410             * @return the previous, current, and next layout
1411             * @throws com.liferay.portal.NoSuchLayoutException if a layout with the primary key could not be found
1412             * @throws SystemException if a system exception occurred
1413             */
1414            public Layout[] findByGroupId_PrevAndNext(long plid, long groupId,
1415                    OrderByComparator orderByComparator)
1416                    throws NoSuchLayoutException, SystemException {
1417                    Layout layout = findByPrimaryKey(plid);
1418    
1419                    Session session = null;
1420    
1421                    try {
1422                            session = openSession();
1423    
1424                            Layout[] array = new LayoutImpl[3];
1425    
1426                            array[0] = getByGroupId_PrevAndNext(session, layout, groupId,
1427                                            orderByComparator, true);
1428    
1429                            array[1] = layout;
1430    
1431                            array[2] = getByGroupId_PrevAndNext(session, layout, groupId,
1432                                            orderByComparator, false);
1433    
1434                            return array;
1435                    }
1436                    catch (Exception e) {
1437                            throw processException(e);
1438                    }
1439                    finally {
1440                            closeSession(session);
1441                    }
1442            }
1443    
1444            protected Layout getByGroupId_PrevAndNext(Session session, Layout layout,
1445                    long groupId, OrderByComparator orderByComparator, boolean previous) {
1446                    StringBundler query = null;
1447    
1448                    if (orderByComparator != null) {
1449                            query = new StringBundler(6 +
1450                                            (orderByComparator.getOrderByFields().length * 6));
1451                    }
1452                    else {
1453                            query = new StringBundler(3);
1454                    }
1455    
1456                    query.append(_SQL_SELECT_LAYOUT_WHERE);
1457    
1458                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1459    
1460                    if (orderByComparator != null) {
1461                            String[] orderByFields = orderByComparator.getOrderByFields();
1462    
1463                            if (orderByFields.length > 0) {
1464                                    query.append(WHERE_AND);
1465                            }
1466    
1467                            for (int i = 0; i < orderByFields.length; i++) {
1468                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1469                                    query.append(orderByFields[i]);
1470    
1471                                    if ((i + 1) < orderByFields.length) {
1472                                            if (orderByComparator.isAscending() ^ previous) {
1473                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1474                                            }
1475                                            else {
1476                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1477                                            }
1478                                    }
1479                                    else {
1480                                            if (orderByComparator.isAscending() ^ previous) {
1481                                                    query.append(WHERE_GREATER_THAN);
1482                                            }
1483                                            else {
1484                                                    query.append(WHERE_LESSER_THAN);
1485                                            }
1486                                    }
1487                            }
1488    
1489                            query.append(ORDER_BY_CLAUSE);
1490    
1491                            for (int i = 0; i < orderByFields.length; i++) {
1492                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1493                                    query.append(orderByFields[i]);
1494    
1495                                    if ((i + 1) < orderByFields.length) {
1496                                            if (orderByComparator.isAscending() ^ previous) {
1497                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1498                                            }
1499                                            else {
1500                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1501                                            }
1502                                    }
1503                                    else {
1504                                            if (orderByComparator.isAscending() ^ previous) {
1505                                                    query.append(ORDER_BY_ASC);
1506                                            }
1507                                            else {
1508                                                    query.append(ORDER_BY_DESC);
1509                                            }
1510                                    }
1511                            }
1512                    }
1513    
1514                    else {
1515                            query.append(LayoutModelImpl.ORDER_BY_JPQL);
1516                    }
1517    
1518                    String sql = query.toString();
1519    
1520                    Query q = session.createQuery(sql);
1521    
1522                    q.setFirstResult(0);
1523                    q.setMaxResults(2);
1524    
1525                    QueryPos qPos = QueryPos.getInstance(q);
1526    
1527                    qPos.add(groupId);
1528    
1529                    if (orderByComparator != null) {
1530                            Object[] values = orderByComparator.getOrderByValues(layout);
1531    
1532                            for (Object value : values) {
1533                                    qPos.add(value);
1534                            }
1535                    }
1536    
1537                    List<Layout> list = q.list();
1538    
1539                    if (list.size() == 2) {
1540                            return list.get(1);
1541                    }
1542                    else {
1543                            return null;
1544                    }
1545            }
1546    
1547            /**
1548             * Filters by the user's permissions and finds all the layouts where groupId = &#63;.
1549             *
1550             * @param groupId the group id to search with
1551             * @return the matching layouts that the user has permission to view
1552             * @throws SystemException if a system exception occurred
1553             */
1554            public List<Layout> filterFindByGroupId(long groupId)
1555                    throws SystemException {
1556                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1557                            QueryUtil.ALL_POS, null);
1558            }
1559    
1560            /**
1561             * Filters by the user's permissions and finds a range of all the layouts where groupId = &#63;.
1562             *
1563             * <p>
1564             * 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.
1565             * </p>
1566             *
1567             * @param groupId the group id to search with
1568             * @param start the lower bound of the range of layouts to return
1569             * @param end the upper bound of the range of layouts to return (not inclusive)
1570             * @return the range of matching layouts that the user has permission to view
1571             * @throws SystemException if a system exception occurred
1572             */
1573            public List<Layout> filterFindByGroupId(long groupId, int start, int end)
1574                    throws SystemException {
1575                    return filterFindByGroupId(groupId, start, end, null);
1576            }
1577    
1578            /**
1579             * Filters by the user's permissions and finds an ordered range of all the layouts where groupId = &#63;.
1580             *
1581             * <p>
1582             * 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.
1583             * </p>
1584             *
1585             * @param groupId the group id to search with
1586             * @param start the lower bound of the range of layouts to return
1587             * @param end the upper bound of the range of layouts to return (not inclusive)
1588             * @param orderByComparator the comparator to order the results by
1589             * @return the ordered range of matching layouts that the user has permission to view
1590             * @throws SystemException if a system exception occurred
1591             */
1592            public List<Layout> filterFindByGroupId(long groupId, int start, int end,
1593                    OrderByComparator orderByComparator) throws SystemException {
1594                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1595                            return findByGroupId(groupId, start, end, orderByComparator);
1596                    }
1597    
1598                    StringBundler query = null;
1599    
1600                    if (orderByComparator != null) {
1601                            query = new StringBundler(3 +
1602                                            (orderByComparator.getOrderByFields().length * 3));
1603                    }
1604                    else {
1605                            query = new StringBundler(3);
1606                    }
1607    
1608                    if (getDB().isSupportsInlineDistinct()) {
1609                            query.append(_FILTER_SQL_SELECT_LAYOUT_WHERE);
1610                    }
1611                    else {
1612                            query.append(_FILTER_SQL_SELECT_LAYOUT_NO_INLINE_DISTINCT_WHERE_1);
1613                    }
1614    
1615                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1616    
1617                    if (!getDB().isSupportsInlineDistinct()) {
1618                            query.append(_FILTER_SQL_SELECT_LAYOUT_NO_INLINE_DISTINCT_WHERE_2);
1619                    }
1620    
1621                    if (orderByComparator != null) {
1622                            if (getDB().isSupportsInlineDistinct()) {
1623                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1624                                            orderByComparator);
1625                            }
1626                            else {
1627                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1628                                            orderByComparator);
1629                            }
1630                    }
1631    
1632                    else {
1633                            if (getDB().isSupportsInlineDistinct()) {
1634                                    query.append(LayoutModelImpl.ORDER_BY_JPQL);
1635                            }
1636                            else {
1637                                    query.append(LayoutModelImpl.ORDER_BY_SQL);
1638                            }
1639                    }
1640    
1641                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1642                                    Layout.class.getName(), _FILTER_COLUMN_PK,
1643                                    _FILTER_COLUMN_USERID, groupId);
1644    
1645                    Session session = null;
1646    
1647                    try {
1648                            session = openSession();
1649    
1650                            SQLQuery q = session.createSQLQuery(sql);
1651    
1652                            if (getDB().isSupportsInlineDistinct()) {
1653                                    q.addEntity(_FILTER_ENTITY_ALIAS, LayoutImpl.class);
1654                            }
1655                            else {
1656                                    q.addEntity(_FILTER_ENTITY_TABLE, LayoutImpl.class);
1657                            }
1658    
1659                            QueryPos qPos = QueryPos.getInstance(q);
1660    
1661                            qPos.add(groupId);
1662    
1663                            return (List<Layout>)QueryUtil.list(q, getDialect(), start, end);
1664                    }
1665                    catch (Exception e) {
1666                            throw processException(e);
1667                    }
1668                    finally {
1669                            closeSession(session);
1670                    }
1671            }
1672    
1673            /**
1674             * Finds all the layouts where companyId = &#63;.
1675             *
1676             * @param companyId the company id to search with
1677             * @return the matching layouts
1678             * @throws SystemException if a system exception occurred
1679             */
1680            public List<Layout> findByCompanyId(long companyId)
1681                    throws SystemException {
1682                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1683                            null);
1684            }
1685    
1686            /**
1687             * Finds a range of all the layouts where companyId = &#63;.
1688             *
1689             * <p>
1690             * 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.
1691             * </p>
1692             *
1693             * @param companyId the company id to search with
1694             * @param start the lower bound of the range of layouts to return
1695             * @param end the upper bound of the range of layouts to return (not inclusive)
1696             * @return the range of matching layouts
1697             * @throws SystemException if a system exception occurred
1698             */
1699            public List<Layout> findByCompanyId(long companyId, int start, int end)
1700                    throws SystemException {
1701                    return findByCompanyId(companyId, start, end, null);
1702            }
1703    
1704            /**
1705             * Finds an ordered range of all the layouts where companyId = &#63;.
1706             *
1707             * <p>
1708             * 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.
1709             * </p>
1710             *
1711             * @param companyId the company id to search with
1712             * @param start the lower bound of the range of layouts to return
1713             * @param end the upper bound of the range of layouts to return (not inclusive)
1714             * @param orderByComparator the comparator to order the results by
1715             * @return the ordered range of matching layouts
1716             * @throws SystemException if a system exception occurred
1717             */
1718            public List<Layout> findByCompanyId(long companyId, int start, int end,
1719                    OrderByComparator orderByComparator) throws SystemException {
1720                    Object[] finderArgs = new Object[] {
1721                                    companyId,
1722                                    
1723                                    String.valueOf(start), String.valueOf(end),
1724                                    String.valueOf(orderByComparator)
1725                            };
1726    
1727                    List<Layout> list = (List<Layout>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_COMPANYID,
1728                                    finderArgs, this);
1729    
1730                    if (list == null) {
1731                            StringBundler query = null;
1732    
1733                            if (orderByComparator != null) {
1734                                    query = new StringBundler(3 +
1735                                                    (orderByComparator.getOrderByFields().length * 3));
1736                            }
1737                            else {
1738                                    query = new StringBundler(3);
1739                            }
1740    
1741                            query.append(_SQL_SELECT_LAYOUT_WHERE);
1742    
1743                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1744    
1745                            if (orderByComparator != null) {
1746                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1747                                            orderByComparator);
1748                            }
1749    
1750                            else {
1751                                    query.append(LayoutModelImpl.ORDER_BY_JPQL);
1752                            }
1753    
1754                            String sql = query.toString();
1755    
1756                            Session session = null;
1757    
1758                            try {
1759                                    session = openSession();
1760    
1761                                    Query q = session.createQuery(sql);
1762    
1763                                    QueryPos qPos = QueryPos.getInstance(q);
1764    
1765                                    qPos.add(companyId);
1766    
1767                                    list = (List<Layout>)QueryUtil.list(q, getDialect(), start, end);
1768                            }
1769                            catch (Exception e) {
1770                                    throw processException(e);
1771                            }
1772                            finally {
1773                                    if (list == null) {
1774                                            FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_COMPANYID,
1775                                                    finderArgs);
1776                                    }
1777                                    else {
1778                                            cacheResult(list);
1779    
1780                                            FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_COMPANYID,
1781                                                    finderArgs, list);
1782                                    }
1783    
1784                                    closeSession(session);
1785                            }
1786                    }
1787    
1788                    return list;
1789            }
1790    
1791            /**
1792             * Finds the first layout in the ordered set where companyId = &#63;.
1793             *
1794             * <p>
1795             * 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.
1796             * </p>
1797             *
1798             * @param companyId the company id to search with
1799             * @param orderByComparator the comparator to order the set by
1800             * @return the first matching layout
1801             * @throws com.liferay.portal.NoSuchLayoutException if a matching layout could not be found
1802             * @throws SystemException if a system exception occurred
1803             */
1804            public Layout findByCompanyId_First(long companyId,
1805                    OrderByComparator orderByComparator)
1806                    throws NoSuchLayoutException, SystemException {
1807                    List<Layout> list = findByCompanyId(companyId, 0, 1, orderByComparator);
1808    
1809                    if (list.isEmpty()) {
1810                            StringBundler msg = new StringBundler(4);
1811    
1812                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1813    
1814                            msg.append("companyId=");
1815                            msg.append(companyId);
1816    
1817                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1818    
1819                            throw new NoSuchLayoutException(msg.toString());
1820                    }
1821                    else {
1822                            return list.get(0);
1823                    }
1824            }
1825    
1826            /**
1827             * Finds the last layout in the ordered set where companyId = &#63;.
1828             *
1829             * <p>
1830             * 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.
1831             * </p>
1832             *
1833             * @param companyId the company id to search with
1834             * @param orderByComparator the comparator to order the set by
1835             * @return the last matching layout
1836             * @throws com.liferay.portal.NoSuchLayoutException if a matching layout could not be found
1837             * @throws SystemException if a system exception occurred
1838             */
1839            public Layout findByCompanyId_Last(long companyId,
1840                    OrderByComparator orderByComparator)
1841                    throws NoSuchLayoutException, SystemException {
1842                    int count = countByCompanyId(companyId);
1843    
1844                    List<Layout> list = findByCompanyId(companyId, count - 1, count,
1845                                    orderByComparator);
1846    
1847                    if (list.isEmpty()) {
1848                            StringBundler msg = new StringBundler(4);
1849    
1850                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1851    
1852                            msg.append("companyId=");
1853                            msg.append(companyId);
1854    
1855                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1856    
1857                            throw new NoSuchLayoutException(msg.toString());
1858                    }
1859                    else {
1860                            return list.get(0);
1861                    }
1862            }
1863    
1864            /**
1865             * Finds the layouts before and after the current layout in the ordered set where companyId = &#63;.
1866             *
1867             * <p>
1868             * 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.
1869             * </p>
1870             *
1871             * @param plid the primary key of the current layout
1872             * @param companyId the company id to search with
1873             * @param orderByComparator the comparator to order the set by
1874             * @return the previous, current, and next layout
1875             * @throws com.liferay.portal.NoSuchLayoutException if a layout with the primary key could not be found
1876             * @throws SystemException if a system exception occurred
1877             */
1878            public Layout[] findByCompanyId_PrevAndNext(long plid, long companyId,
1879                    OrderByComparator orderByComparator)
1880                    throws NoSuchLayoutException, SystemException {
1881                    Layout layout = findByPrimaryKey(plid);
1882    
1883                    Session session = null;
1884    
1885                    try {
1886                            session = openSession();
1887    
1888                            Layout[] array = new LayoutImpl[3];
1889    
1890                            array[0] = getByCompanyId_PrevAndNext(session, layout, companyId,
1891                                            orderByComparator, true);
1892    
1893                            array[1] = layout;
1894    
1895                            array[2] = getByCompanyId_PrevAndNext(session, layout, companyId,
1896                                            orderByComparator, false);
1897    
1898                            return array;
1899                    }
1900                    catch (Exception e) {
1901                            throw processException(e);
1902                    }
1903                    finally {
1904                            closeSession(session);
1905                    }
1906            }
1907    
1908            protected Layout getByCompanyId_PrevAndNext(Session session, Layout layout,
1909                    long companyId, OrderByComparator orderByComparator, boolean previous) {
1910                    StringBundler query = null;
1911    
1912                    if (orderByComparator != null) {
1913                            query = new StringBundler(6 +
1914                                            (orderByComparator.getOrderByFields().length * 6));
1915                    }
1916                    else {
1917                            query = new StringBundler(3);
1918                    }
1919    
1920                    query.append(_SQL_SELECT_LAYOUT_WHERE);
1921    
1922                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1923    
1924                    if (orderByComparator != null) {
1925                            String[] orderByFields = orderByComparator.getOrderByFields();
1926    
1927                            if (orderByFields.length > 0) {
1928                                    query.append(WHERE_AND);
1929                            }
1930    
1931                            for (int i = 0; i < orderByFields.length; i++) {
1932                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1933                                    query.append(orderByFields[i]);
1934    
1935                                    if ((i + 1) < orderByFields.length) {
1936                                            if (orderByComparator.isAscending() ^ previous) {
1937                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1938                                            }
1939                                            else {
1940                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1941                                            }
1942                                    }
1943                                    else {
1944                                            if (orderByComparator.isAscending() ^ previous) {
1945                                                    query.append(WHERE_GREATER_THAN);
1946                                            }
1947                                            else {
1948                                                    query.append(WHERE_LESSER_THAN);
1949                                            }
1950                                    }
1951                            }
1952    
1953                            query.append(ORDER_BY_CLAUSE);
1954    
1955                            for (int i = 0; i < orderByFields.length; i++) {
1956                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1957                                    query.append(orderByFields[i]);
1958    
1959                                    if ((i + 1) < orderByFields.length) {
1960                                            if (orderByComparator.isAscending() ^ previous) {
1961                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1962                                            }
1963                                            else {
1964                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1965                                            }
1966                                    }
1967                                    else {
1968                                            if (orderByComparator.isAscending() ^ previous) {
1969                                                    query.append(ORDER_BY_ASC);
1970                                            }
1971                                            else {
1972                                                    query.append(ORDER_BY_DESC);
1973                                            }
1974                                    }
1975                            }
1976                    }
1977    
1978                    else {
1979                            query.append(LayoutModelImpl.ORDER_BY_JPQL);
1980                    }
1981    
1982                    String sql = query.toString();
1983    
1984                    Query q = session.createQuery(sql);
1985    
1986                    q.setFirstResult(0);
1987                    q.setMaxResults(2);
1988    
1989                    QueryPos qPos = QueryPos.getInstance(q);
1990    
1991                    qPos.add(companyId);
1992    
1993                    if (orderByComparator != null) {
1994                            Object[] values = orderByComparator.getOrderByValues(layout);
1995    
1996                            for (Object value : values) {
1997                                    qPos.add(value);
1998                            }
1999                    }
2000    
2001                    List<Layout> list = q.list();
2002    
2003                    if (list.size() == 2) {
2004                            return list.get(1);
2005                    }
2006                    else {
2007                            return null;
2008                    }
2009            }
2010    
2011            /**
2012             * Finds the layout where dlFolderId = &#63; or throws a {@link com.liferay.portal.NoSuchLayoutException} if it could not be found.
2013             *
2014             * @param dlFolderId the dl folder id to search with
2015             * @return the matching layout
2016             * @throws com.liferay.portal.NoSuchLayoutException if a matching layout could not be found
2017             * @throws SystemException if a system exception occurred
2018             */
2019            public Layout findByDLFolderId(long dlFolderId)
2020                    throws NoSuchLayoutException, SystemException {
2021                    Layout layout = fetchByDLFolderId(dlFolderId);
2022    
2023                    if (layout == null) {
2024                            StringBundler msg = new StringBundler(4);
2025    
2026                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2027    
2028                            msg.append("dlFolderId=");
2029                            msg.append(dlFolderId);
2030    
2031                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2032    
2033                            if (_log.isWarnEnabled()) {
2034                                    _log.warn(msg.toString());
2035                            }
2036    
2037                            throw new NoSuchLayoutException(msg.toString());
2038                    }
2039    
2040                    return layout;
2041            }
2042    
2043            /**
2044             * Finds the layout where dlFolderId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
2045             *
2046             * @param dlFolderId the dl folder id to search with
2047             * @return the matching layout, or <code>null</code> if a matching layout could not be found
2048             * @throws SystemException if a system exception occurred
2049             */
2050            public Layout fetchByDLFolderId(long dlFolderId) throws SystemException {
2051                    return fetchByDLFolderId(dlFolderId, true);
2052            }
2053    
2054            /**
2055             * Finds the layout where dlFolderId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
2056             *
2057             * @param dlFolderId the dl folder id to search with
2058             * @return the matching layout, or <code>null</code> if a matching layout could not be found
2059             * @throws SystemException if a system exception occurred
2060             */
2061            public Layout fetchByDLFolderId(long dlFolderId, boolean retrieveFromCache)
2062                    throws SystemException {
2063                    Object[] finderArgs = new Object[] { dlFolderId };
2064    
2065                    Object result = null;
2066    
2067                    if (retrieveFromCache) {
2068                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_DLFOLDERID,
2069                                            finderArgs, this);
2070                    }
2071    
2072                    if (result == null) {
2073                            StringBundler query = new StringBundler(3);
2074    
2075                            query.append(_SQL_SELECT_LAYOUT_WHERE);
2076    
2077                            query.append(_FINDER_COLUMN_DLFOLDERID_DLFOLDERID_2);
2078    
2079                            query.append(LayoutModelImpl.ORDER_BY_JPQL);
2080    
2081                            String sql = query.toString();
2082    
2083                            Session session = null;
2084    
2085                            try {
2086                                    session = openSession();
2087    
2088                                    Query q = session.createQuery(sql);
2089    
2090                                    QueryPos qPos = QueryPos.getInstance(q);
2091    
2092                                    qPos.add(dlFolderId);
2093    
2094                                    List<Layout> list = q.list();
2095    
2096                                    result = list;
2097    
2098                                    Layout layout = null;
2099    
2100                                    if (list.isEmpty()) {
2101                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_DLFOLDERID,
2102                                                    finderArgs, list);
2103                                    }
2104                                    else {
2105                                            layout = list.get(0);
2106    
2107                                            cacheResult(layout);
2108    
2109                                            if ((layout.getDlFolderId() != dlFolderId)) {
2110                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_DLFOLDERID,
2111                                                            finderArgs, layout);
2112                                            }
2113                                    }
2114    
2115                                    return layout;
2116                            }
2117                            catch (Exception e) {
2118                                    throw processException(e);
2119                            }
2120                            finally {
2121                                    if (result == null) {
2122                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_DLFOLDERID,
2123                                                    finderArgs);
2124                                    }
2125    
2126                                    closeSession(session);
2127                            }
2128                    }
2129                    else {
2130                            if (result instanceof List<?>) {
2131                                    return null;
2132                            }
2133                            else {
2134                                    return (Layout)result;
2135                            }
2136                    }
2137            }
2138    
2139            /**
2140             * Finds the layout where iconImageId = &#63; or throws a {@link com.liferay.portal.NoSuchLayoutException} if it could not be found.
2141             *
2142             * @param iconImageId the icon image id to search with
2143             * @return the matching layout
2144             * @throws com.liferay.portal.NoSuchLayoutException if a matching layout could not be found
2145             * @throws SystemException if a system exception occurred
2146             */
2147            public Layout findByIconImageId(long iconImageId)
2148                    throws NoSuchLayoutException, SystemException {
2149                    Layout layout = fetchByIconImageId(iconImageId);
2150    
2151                    if (layout == null) {
2152                            StringBundler msg = new StringBundler(4);
2153    
2154                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2155    
2156                            msg.append("iconImageId=");
2157                            msg.append(iconImageId);
2158    
2159                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2160    
2161                            if (_log.isWarnEnabled()) {
2162                                    _log.warn(msg.toString());
2163                            }
2164    
2165                            throw new NoSuchLayoutException(msg.toString());
2166                    }
2167    
2168                    return layout;
2169            }
2170    
2171            /**
2172             * Finds the layout where iconImageId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
2173             *
2174             * @param iconImageId the icon image id to search with
2175             * @return the matching layout, or <code>null</code> if a matching layout could not be found
2176             * @throws SystemException if a system exception occurred
2177             */
2178            public Layout fetchByIconImageId(long iconImageId)
2179                    throws SystemException {
2180                    return fetchByIconImageId(iconImageId, true);
2181            }
2182    
2183            /**
2184             * Finds the layout where iconImageId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
2185             *
2186             * @param iconImageId the icon image id to search with
2187             * @return the matching layout, or <code>null</code> if a matching layout could not be found
2188             * @throws SystemException if a system exception occurred
2189             */
2190            public Layout fetchByIconImageId(long iconImageId, boolean retrieveFromCache)
2191                    throws SystemException {
2192                    Object[] finderArgs = new Object[] { iconImageId };
2193    
2194                    Object result = null;
2195    
2196                    if (retrieveFromCache) {
2197                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_ICONIMAGEID,
2198                                            finderArgs, this);
2199                    }
2200    
2201                    if (result == null) {
2202                            StringBundler query = new StringBundler(3);
2203    
2204                            query.append(_SQL_SELECT_LAYOUT_WHERE);
2205    
2206                            query.append(_FINDER_COLUMN_ICONIMAGEID_ICONIMAGEID_2);
2207    
2208                            query.append(LayoutModelImpl.ORDER_BY_JPQL);
2209    
2210                            String sql = query.toString();
2211    
2212                            Session session = null;
2213    
2214                            try {
2215                                    session = openSession();
2216    
2217                                    Query q = session.createQuery(sql);
2218    
2219                                    QueryPos qPos = QueryPos.getInstance(q);
2220    
2221                                    qPos.add(iconImageId);
2222    
2223                                    List<Layout> list = q.list();
2224    
2225                                    result = list;
2226    
2227                                    Layout layout = null;
2228    
2229                                    if (list.isEmpty()) {
2230                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_ICONIMAGEID,
2231                                                    finderArgs, list);
2232                                    }
2233                                    else {
2234                                            layout = list.get(0);
2235    
2236                                            cacheResult(layout);
2237    
2238                                            if ((layout.getIconImageId() != iconImageId)) {
2239                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_ICONIMAGEID,
2240                                                            finderArgs, layout);
2241                                            }
2242                                    }
2243    
2244                                    return layout;
2245                            }
2246                            catch (Exception e) {
2247                                    throw processException(e);
2248                            }
2249                            finally {
2250                                    if (result == null) {
2251                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_ICONIMAGEID,
2252                                                    finderArgs);
2253                                    }
2254    
2255                                    closeSession(session);
2256                            }
2257                    }
2258                    else {
2259                            if (result instanceof List<?>) {
2260                                    return null;
2261                            }
2262                            else {
2263                                    return (Layout)result;
2264                            }
2265                    }
2266            }
2267    
2268            /**
2269             * Finds all the layouts where groupId = &#63; and privateLayout = &#63;.
2270             *
2271             * @param groupId the group id to search with
2272             * @param privateLayout the private layout to search with
2273             * @return the matching layouts
2274             * @throws SystemException if a system exception occurred
2275             */
2276            public List<Layout> findByG_P(long groupId, boolean privateLayout)
2277                    throws SystemException {
2278                    return findByG_P(groupId, privateLayout, QueryUtil.ALL_POS,
2279                            QueryUtil.ALL_POS, null);
2280            }
2281    
2282            /**
2283             * Finds a range of all the layouts where groupId = &#63; and privateLayout = &#63;.
2284             *
2285             * <p>
2286             * 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.
2287             * </p>
2288             *
2289             * @param groupId the group id to search with
2290             * @param privateLayout the private layout to search with
2291             * @param start the lower bound of the range of layouts to return
2292             * @param end the upper bound of the range of layouts to return (not inclusive)
2293             * @return the range of matching layouts
2294             * @throws SystemException if a system exception occurred
2295             */
2296            public List<Layout> findByG_P(long groupId, boolean privateLayout,
2297                    int start, int end) throws SystemException {
2298                    return findByG_P(groupId, privateLayout, start, end, null);
2299            }
2300    
2301            /**
2302             * Finds an ordered range of all the layouts where groupId = &#63; and privateLayout = &#63;.
2303             *
2304             * <p>
2305             * 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.
2306             * </p>
2307             *
2308             * @param groupId the group id to search with
2309             * @param privateLayout the private layout to search with
2310             * @param start the lower bound of the range of layouts to return
2311             * @param end the upper bound of the range of layouts to return (not inclusive)
2312             * @param orderByComparator the comparator to order the results by
2313             * @return the ordered range of matching layouts
2314             * @throws SystemException if a system exception occurred
2315             */
2316            public List<Layout> findByG_P(long groupId, boolean privateLayout,
2317                    int start, int end, OrderByComparator orderByComparator)
2318                    throws SystemException {
2319                    Object[] finderArgs = new Object[] {
2320                                    groupId, privateLayout,
2321                                    
2322                                    String.valueOf(start), String.valueOf(end),
2323                                    String.valueOf(orderByComparator)
2324                            };
2325    
2326                    List<Layout> list = (List<Layout>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_P,
2327                                    finderArgs, this);
2328    
2329                    if (list == null) {
2330                            StringBundler query = null;
2331    
2332                            if (orderByComparator != null) {
2333                                    query = new StringBundler(4 +
2334                                                    (orderByComparator.getOrderByFields().length * 3));
2335                            }
2336                            else {
2337                                    query = new StringBundler(4);
2338                            }
2339    
2340                            query.append(_SQL_SELECT_LAYOUT_WHERE);
2341    
2342                            query.append(_FINDER_COLUMN_G_P_GROUPID_2);
2343    
2344                            query.append(_FINDER_COLUMN_G_P_PRIVATELAYOUT_2);
2345    
2346                            if (orderByComparator != null) {
2347                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2348                                            orderByComparator);
2349                            }
2350    
2351                            else {
2352                                    query.append(LayoutModelImpl.ORDER_BY_JPQL);
2353                            }
2354    
2355                            String sql = query.toString();
2356    
2357                            Session session = null;
2358    
2359                            try {
2360                                    session = openSession();
2361    
2362                                    Query q = session.createQuery(sql);
2363    
2364                                    QueryPos qPos = QueryPos.getInstance(q);
2365    
2366                                    qPos.add(groupId);
2367    
2368                                    qPos.add(privateLayout);
2369    
2370                                    list = (List<Layout>)QueryUtil.list(q, getDialect(), start, end);
2371                            }
2372                            catch (Exception e) {
2373                                    throw processException(e);
2374                            }
2375                            finally {
2376                                    if (list == null) {
2377                                            FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_G_P,
2378                                                    finderArgs);
2379                                    }
2380                                    else {
2381                                            cacheResult(list);
2382    
2383                                            FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_P,
2384                                                    finderArgs, list);
2385                                    }
2386    
2387                                    closeSession(session);
2388                            }
2389                    }
2390    
2391                    return list;
2392            }
2393    
2394            /**
2395             * Finds the first layout in the ordered set where groupId = &#63; and privateLayout = &#63;.
2396             *
2397             * <p>
2398             * 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.
2399             * </p>
2400             *
2401             * @param groupId the group id to search with
2402             * @param privateLayout the private layout to search with
2403             * @param orderByComparator the comparator to order the set by
2404             * @return the first matching layout
2405             * @throws com.liferay.portal.NoSuchLayoutException if a matching layout could not be found
2406             * @throws SystemException if a system exception occurred
2407             */
2408            public Layout findByG_P_First(long groupId, boolean privateLayout,
2409                    OrderByComparator orderByComparator)
2410                    throws NoSuchLayoutException, SystemException {
2411                    List<Layout> list = findByG_P(groupId, privateLayout, 0, 1,
2412                                    orderByComparator);
2413    
2414                    if (list.isEmpty()) {
2415                            StringBundler msg = new StringBundler(6);
2416    
2417                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2418    
2419                            msg.append("groupId=");
2420                            msg.append(groupId);
2421    
2422                            msg.append(", privateLayout=");
2423                            msg.append(privateLayout);
2424    
2425                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2426    
2427                            throw new NoSuchLayoutException(msg.toString());
2428                    }
2429                    else {
2430                            return list.get(0);
2431                    }
2432            }
2433    
2434            /**
2435             * Finds the last layout in the ordered set where groupId = &#63; and privateLayout = &#63;.
2436             *
2437             * <p>
2438             * 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.
2439             * </p>
2440             *
2441             * @param groupId the group id to search with
2442             * @param privateLayout the private layout to search with
2443             * @param orderByComparator the comparator to order the set by
2444             * @return the last matching layout
2445             * @throws com.liferay.portal.NoSuchLayoutException if a matching layout could not be found
2446             * @throws SystemException if a system exception occurred
2447             */
2448            public Layout findByG_P_Last(long groupId, boolean privateLayout,
2449                    OrderByComparator orderByComparator)
2450                    throws NoSuchLayoutException, SystemException {
2451                    int count = countByG_P(groupId, privateLayout);
2452    
2453                    List<Layout> list = findByG_P(groupId, privateLayout, count - 1, count,
2454                                    orderByComparator);
2455    
2456                    if (list.isEmpty()) {
2457                            StringBundler msg = new StringBundler(6);
2458    
2459                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2460    
2461                            msg.append("groupId=");
2462                            msg.append(groupId);
2463    
2464                            msg.append(", privateLayout=");
2465                            msg.append(privateLayout);
2466    
2467                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2468    
2469                            throw new NoSuchLayoutException(msg.toString());
2470                    }
2471                    else {
2472                            return list.get(0);
2473                    }
2474            }
2475    
2476            /**
2477             * Finds the layouts before and after the current layout in the ordered set where groupId = &#63; and privateLayout = &#63;.
2478             *
2479             * <p>
2480             * 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.
2481             * </p>
2482             *
2483             * @param plid the primary key of the current layout
2484             * @param groupId the group id to search with
2485             * @param privateLayout the private layout to search with
2486             * @param orderByComparator the comparator to order the set by
2487             * @return the previous, current, and next layout
2488             * @throws com.liferay.portal.NoSuchLayoutException if a layout with the primary key could not be found
2489             * @throws SystemException if a system exception occurred
2490             */
2491            public Layout[] findByG_P_PrevAndNext(long plid, long groupId,
2492                    boolean privateLayout, OrderByComparator orderByComparator)
2493                    throws NoSuchLayoutException, SystemException {
2494                    Layout layout = findByPrimaryKey(plid);
2495    
2496                    Session session = null;
2497    
2498                    try {
2499                            session = openSession();
2500    
2501                            Layout[] array = new LayoutImpl[3];
2502    
2503                            array[0] = getByG_P_PrevAndNext(session, layout, groupId,
2504                                            privateLayout, orderByComparator, true);
2505    
2506                            array[1] = layout;
2507    
2508                            array[2] = getByG_P_PrevAndNext(session, layout, groupId,
2509                                            privateLayout, orderByComparator, false);
2510    
2511                            return array;
2512                    }
2513                    catch (Exception e) {
2514                            throw processException(e);
2515                    }
2516                    finally {
2517                            closeSession(session);
2518                    }
2519            }
2520    
2521            protected Layout getByG_P_PrevAndNext(Session session, Layout layout,
2522                    long groupId, boolean privateLayout,
2523                    OrderByComparator orderByComparator, boolean previous) {
2524                    StringBundler query = null;
2525    
2526                    if (orderByComparator != null) {
2527                            query = new StringBundler(6 +
2528                                            (orderByComparator.getOrderByFields().length * 6));
2529                    }
2530                    else {
2531                            query = new StringBundler(3);
2532                    }
2533    
2534                    query.append(_SQL_SELECT_LAYOUT_WHERE);
2535    
2536                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
2537    
2538                    query.append(_FINDER_COLUMN_G_P_PRIVATELAYOUT_2);
2539    
2540                    if (orderByComparator != null) {
2541                            String[] orderByFields = orderByComparator.getOrderByFields();
2542    
2543                            if (orderByFields.length > 0) {
2544                                    query.append(WHERE_AND);
2545                            }
2546    
2547                            for (int i = 0; i < orderByFields.length; i++) {
2548                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2549                                    query.append(orderByFields[i]);
2550    
2551                                    if ((i + 1) < orderByFields.length) {
2552                                            if (orderByComparator.isAscending() ^ previous) {
2553                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2554                                            }
2555                                            else {
2556                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2557                                            }
2558                                    }
2559                                    else {
2560                                            if (orderByComparator.isAscending() ^ previous) {
2561                                                    query.append(WHERE_GREATER_THAN);
2562                                            }
2563                                            else {
2564                                                    query.append(WHERE_LESSER_THAN);
2565                                            }
2566                                    }
2567                            }
2568    
2569                            query.append(ORDER_BY_CLAUSE);
2570    
2571                            for (int i = 0; i < orderByFields.length; i++) {
2572                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2573                                    query.append(orderByFields[i]);
2574    
2575                                    if ((i + 1) < orderByFields.length) {
2576                                            if (orderByComparator.isAscending() ^ previous) {
2577                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2578                                            }
2579                                            else {
2580                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2581                                            }
2582                                    }
2583                                    else {
2584                                            if (orderByComparator.isAscending() ^ previous) {
2585                                                    query.append(ORDER_BY_ASC);
2586                                            }
2587                                            else {
2588                                                    query.append(ORDER_BY_DESC);
2589                                            }
2590                                    }
2591                            }
2592                    }
2593    
2594                    else {
2595                            query.append(LayoutModelImpl.ORDER_BY_JPQL);
2596                    }
2597    
2598                    String sql = query.toString();
2599    
2600                    Query q = session.createQuery(sql);
2601    
2602                    q.setFirstResult(0);
2603                    q.setMaxResults(2);
2604    
2605                    QueryPos qPos = QueryPos.getInstance(q);
2606    
2607                    qPos.add(groupId);
2608    
2609                    qPos.add(privateLayout);
2610    
2611                    if (orderByComparator != null) {
2612                            Object[] values = orderByComparator.getOrderByValues(layout);
2613    
2614                            for (Object value : values) {
2615                                    qPos.add(value);
2616                            }
2617                    }
2618    
2619                    List<Layout> list = q.list();
2620    
2621                    if (list.size() == 2) {
2622                            return list.get(1);
2623                    }
2624                    else {
2625                            return null;
2626                    }
2627            }
2628    
2629            /**
2630             * Filters by the user's permissions and finds all the layouts where groupId = &#63; and privateLayout = &#63;.
2631             *
2632             * @param groupId the group id to search with
2633             * @param privateLayout the private layout to search with
2634             * @return the matching layouts that the user has permission to view
2635             * @throws SystemException if a system exception occurred
2636             */
2637            public List<Layout> filterFindByG_P(long groupId, boolean privateLayout)
2638                    throws SystemException {
2639                    return filterFindByG_P(groupId, privateLayout, QueryUtil.ALL_POS,
2640                            QueryUtil.ALL_POS, null);
2641            }
2642    
2643            /**
2644             * Filters by the user's permissions and finds a range of all the layouts where groupId = &#63; and privateLayout = &#63;.
2645             *
2646             * <p>
2647             * 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.
2648             * </p>
2649             *
2650             * @param groupId the group id to search with
2651             * @param privateLayout the private layout to search with
2652             * @param start the lower bound of the range of layouts to return
2653             * @param end the upper bound of the range of layouts to return (not inclusive)
2654             * @return the range of matching layouts that the user has permission to view
2655             * @throws SystemException if a system exception occurred
2656             */
2657            public List<Layout> filterFindByG_P(long groupId, boolean privateLayout,
2658                    int start, int end) throws SystemException {
2659                    return filterFindByG_P(groupId, privateLayout, start, end, null);
2660            }
2661    
2662            /**
2663             * Filters by the user's permissions and finds an ordered range of all the layouts where groupId = &#63; and privateLayout = &#63;.
2664             *
2665             * <p>
2666             * 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.
2667             * </p>
2668             *
2669             * @param groupId the group id to search with
2670             * @param privateLayout the private layout to search with
2671             * @param start the lower bound of the range of layouts to return
2672             * @param end the upper bound of the range of layouts to return (not inclusive)
2673             * @param orderByComparator the comparator to order the results by
2674             * @return the ordered range of matching layouts that the user has permission to view
2675             * @throws SystemException if a system exception occurred
2676             */
2677            public List<Layout> filterFindByG_P(long groupId, boolean privateLayout,
2678                    int start, int end, OrderByComparator orderByComparator)
2679                    throws SystemException {
2680                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2681                            return findByG_P(groupId, privateLayout, start, end,
2682                                    orderByComparator);
2683                    }
2684    
2685                    StringBundler query = null;
2686    
2687                    if (orderByComparator != null) {
2688                            query = new StringBundler(4 +
2689                                            (orderByComparator.getOrderByFields().length * 3));
2690                    }
2691                    else {
2692                            query = new StringBundler(4);
2693                    }
2694    
2695                    if (getDB().isSupportsInlineDistinct()) {
2696                            query.append(_FILTER_SQL_SELECT_LAYOUT_WHERE);
2697                    }
2698                    else {
2699                            query.append(_FILTER_SQL_SELECT_LAYOUT_NO_INLINE_DISTINCT_WHERE_1);
2700                    }
2701    
2702                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
2703    
2704                    query.append(_FINDER_COLUMN_G_P_PRIVATELAYOUT_2);
2705    
2706                    if (!getDB().isSupportsInlineDistinct()) {
2707                            query.append(_FILTER_SQL_SELECT_LAYOUT_NO_INLINE_DISTINCT_WHERE_2);
2708                    }
2709    
2710                    if (orderByComparator != null) {
2711                            if (getDB().isSupportsInlineDistinct()) {
2712                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2713                                            orderByComparator);
2714                            }
2715                            else {
2716                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2717                                            orderByComparator);
2718                            }
2719                    }
2720    
2721                    else {
2722                            if (getDB().isSupportsInlineDistinct()) {
2723                                    query.append(LayoutModelImpl.ORDER_BY_JPQL);
2724                            }
2725                            else {
2726                                    query.append(LayoutModelImpl.ORDER_BY_SQL);
2727                            }
2728                    }
2729    
2730                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2731                                    Layout.class.getName(), _FILTER_COLUMN_PK,
2732                                    _FILTER_COLUMN_USERID, groupId);
2733    
2734                    Session session = null;
2735    
2736                    try {
2737                            session = openSession();
2738    
2739                            SQLQuery q = session.createSQLQuery(sql);
2740    
2741                            if (getDB().isSupportsInlineDistinct()) {
2742                                    q.addEntity(_FILTER_ENTITY_ALIAS, LayoutImpl.class);
2743                            }
2744                            else {
2745                                    q.addEntity(_FILTER_ENTITY_TABLE, LayoutImpl.class);
2746                            }
2747    
2748                            QueryPos qPos = QueryPos.getInstance(q);
2749    
2750                            qPos.add(groupId);
2751    
2752                            qPos.add(privateLayout);
2753    
2754                            return (List<Layout>)QueryUtil.list(q, getDialect(), start, end);
2755                    }
2756                    catch (Exception e) {
2757                            throw processException(e);
2758                    }
2759                    finally {
2760                            closeSession(session);
2761                    }
2762            }
2763    
2764            /**
2765             * Finds 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.
2766             *
2767             * @param groupId the group id to search with
2768             * @param privateLayout the private layout to search with
2769             * @param layoutId the layout id to search with
2770             * @return the matching layout
2771             * @throws com.liferay.portal.NoSuchLayoutException if a matching layout could not be found
2772             * @throws SystemException if a system exception occurred
2773             */
2774            public Layout findByG_P_L(long groupId, boolean privateLayout, long layoutId)
2775                    throws NoSuchLayoutException, SystemException {
2776                    Layout layout = fetchByG_P_L(groupId, privateLayout, layoutId);
2777    
2778                    if (layout == null) {
2779                            StringBundler msg = new StringBundler(8);
2780    
2781                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2782    
2783                            msg.append("groupId=");
2784                            msg.append(groupId);
2785    
2786                            msg.append(", privateLayout=");
2787                            msg.append(privateLayout);
2788    
2789                            msg.append(", layoutId=");
2790                            msg.append(layoutId);
2791    
2792                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2793    
2794                            if (_log.isWarnEnabled()) {
2795                                    _log.warn(msg.toString());
2796                            }
2797    
2798                            throw new NoSuchLayoutException(msg.toString());
2799                    }
2800    
2801                    return layout;
2802            }
2803    
2804            /**
2805             * Finds 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.
2806             *
2807             * @param groupId the group id to search with
2808             * @param privateLayout the private layout to search with
2809             * @param layoutId the layout id to search with
2810             * @return the matching layout, or <code>null</code> if a matching layout could not be found
2811             * @throws SystemException if a system exception occurred
2812             */
2813            public Layout fetchByG_P_L(long groupId, boolean privateLayout,
2814                    long layoutId) throws SystemException {
2815                    return fetchByG_P_L(groupId, privateLayout, layoutId, true);
2816            }
2817    
2818            /**
2819             * Finds 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.
2820             *
2821             * @param groupId the group id to search with
2822             * @param privateLayout the private layout to search with
2823             * @param layoutId the layout id to search with
2824             * @return the matching layout, or <code>null</code> if a matching layout could not be found
2825             * @throws SystemException if a system exception occurred
2826             */
2827            public Layout fetchByG_P_L(long groupId, boolean privateLayout,
2828                    long layoutId, boolean retrieveFromCache) throws SystemException {
2829                    Object[] finderArgs = new Object[] { groupId, privateLayout, layoutId };
2830    
2831                    Object result = null;
2832    
2833                    if (retrieveFromCache) {
2834                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_P_L,
2835                                            finderArgs, this);
2836                    }
2837    
2838                    if (result == null) {
2839                            StringBundler query = new StringBundler(5);
2840    
2841                            query.append(_SQL_SELECT_LAYOUT_WHERE);
2842    
2843                            query.append(_FINDER_COLUMN_G_P_L_GROUPID_2);
2844    
2845                            query.append(_FINDER_COLUMN_G_P_L_PRIVATELAYOUT_2);
2846    
2847                            query.append(_FINDER_COLUMN_G_P_L_LAYOUTID_2);
2848    
2849                            query.append(LayoutModelImpl.ORDER_BY_JPQL);
2850    
2851                            String sql = query.toString();
2852    
2853                            Session session = null;
2854    
2855                            try {
2856                                    session = openSession();
2857    
2858                                    Query q = session.createQuery(sql);
2859    
2860                                    QueryPos qPos = QueryPos.getInstance(q);
2861    
2862                                    qPos.add(groupId);
2863    
2864                                    qPos.add(privateLayout);
2865    
2866                                    qPos.add(layoutId);
2867    
2868                                    List<Layout> list = q.list();
2869    
2870                                    result = list;
2871    
2872                                    Layout layout = null;
2873    
2874                                    if (list.isEmpty()) {
2875                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_L,
2876                                                    finderArgs, list);
2877                                    }
2878                                    else {
2879                                            layout = list.get(0);
2880    
2881                                            cacheResult(layout);
2882    
2883                                            if ((layout.getGroupId() != groupId) ||
2884                                                            (layout.getPrivateLayout() != privateLayout) ||
2885                                                            (layout.getLayoutId() != layoutId)) {
2886                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_L,
2887                                                            finderArgs, layout);
2888                                            }
2889                                    }
2890    
2891                                    return layout;
2892                            }
2893                            catch (Exception e) {
2894                                    throw processException(e);
2895                            }
2896                            finally {
2897                                    if (result == null) {
2898                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P_L,
2899                                                    finderArgs);
2900                                    }
2901    
2902                                    closeSession(session);
2903                            }
2904                    }
2905                    else {
2906                            if (result instanceof List<?>) {
2907                                    return null;
2908                            }
2909                            else {
2910                                    return (Layout)result;
2911                            }
2912                    }
2913            }
2914    
2915            /**
2916             * Finds all the layouts where groupId = &#63; and privateLayout = &#63; and parentLayoutId = &#63;.
2917             *
2918             * @param groupId the group id to search with
2919             * @param privateLayout the private layout to search with
2920             * @param parentLayoutId the parent layout id to search with
2921             * @return the matching layouts
2922             * @throws SystemException if a system exception occurred
2923             */
2924            public List<Layout> findByG_P_P(long groupId, boolean privateLayout,
2925                    long parentLayoutId) throws SystemException {
2926                    return findByG_P_P(groupId, privateLayout, parentLayoutId,
2927                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2928            }
2929    
2930            /**
2931             * Finds a range of all the layouts where groupId = &#63; and privateLayout = &#63; and parentLayoutId = &#63;.
2932             *
2933             * <p>
2934             * 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.
2935             * </p>
2936             *
2937             * @param groupId the group id to search with
2938             * @param privateLayout the private layout to search with
2939             * @param parentLayoutId the parent layout id to search with
2940             * @param start the lower bound of the range of layouts to return
2941             * @param end the upper bound of the range of layouts to return (not inclusive)
2942             * @return the range of matching layouts
2943             * @throws SystemException if a system exception occurred
2944             */
2945            public List<Layout> findByG_P_P(long groupId, boolean privateLayout,
2946                    long parentLayoutId, int start, int end) throws SystemException {
2947                    return findByG_P_P(groupId, privateLayout, parentLayoutId, start, end,
2948                            null);
2949            }
2950    
2951            /**
2952             * Finds an ordered range of all the layouts where groupId = &#63; and privateLayout = &#63; and parentLayoutId = &#63;.
2953             *
2954             * <p>
2955             * 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.
2956             * </p>
2957             *
2958             * @param groupId the group id to search with
2959             * @param privateLayout the private layout to search with
2960             * @param parentLayoutId the parent layout id to search with
2961             * @param start the lower bound of the range of layouts to return
2962             * @param end the upper bound of the range of layouts to return (not inclusive)
2963             * @param orderByComparator the comparator to order the results by
2964             * @return the ordered range of matching layouts
2965             * @throws SystemException if a system exception occurred
2966             */
2967            public List<Layout> findByG_P_P(long groupId, boolean privateLayout,
2968                    long parentLayoutId, int start, int end,
2969                    OrderByComparator orderByComparator) throws SystemException {
2970                    Object[] finderArgs = new Object[] {
2971                                    groupId, privateLayout, parentLayoutId,
2972                                    
2973                                    String.valueOf(start), String.valueOf(end),
2974                                    String.valueOf(orderByComparator)
2975                            };
2976    
2977                    List<Layout> list = (List<Layout>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_P_P,
2978                                    finderArgs, this);
2979    
2980                    if (list == null) {
2981                            StringBundler query = null;
2982    
2983                            if (orderByComparator != null) {
2984                                    query = new StringBundler(5 +
2985                                                    (orderByComparator.getOrderByFields().length * 3));
2986                            }
2987                            else {
2988                                    query = new StringBundler(5);
2989                            }
2990    
2991                            query.append(_SQL_SELECT_LAYOUT_WHERE);
2992    
2993                            query.append(_FINDER_COLUMN_G_P_P_GROUPID_2);
2994    
2995                            query.append(_FINDER_COLUMN_G_P_P_PRIVATELAYOUT_2);
2996    
2997                            query.append(_FINDER_COLUMN_G_P_P_PARENTLAYOUTID_2);
2998    
2999                            if (orderByComparator != null) {
3000                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3001                                            orderByComparator);
3002                            }
3003    
3004                            else {
3005                                    query.append(LayoutModelImpl.ORDER_BY_JPQL);
3006                            }
3007    
3008                            String sql = query.toString();
3009    
3010                            Session session = null;
3011    
3012                            try {
3013                                    session = openSession();
3014    
3015                                    Query q = session.createQuery(sql);
3016    
3017                                    QueryPos qPos = QueryPos.getInstance(q);
3018    
3019                                    qPos.add(groupId);
3020    
3021                                    qPos.add(privateLayout);
3022    
3023                                    qPos.add(parentLayoutId);
3024    
3025                                    list = (List<Layout>)QueryUtil.list(q, getDialect(), start, end);
3026                            }
3027                            catch (Exception e) {
3028                                    throw processException(e);
3029                            }
3030                            finally {
3031                                    if (list == null) {
3032                                            FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_G_P_P,
3033                                                    finderArgs);
3034                                    }
3035                                    else {
3036                                            cacheResult(list);
3037    
3038                                            FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_P_P,
3039                                                    finderArgs, list);
3040                                    }
3041    
3042                                    closeSession(session);
3043                            }
3044                    }
3045    
3046                    return list;
3047            }
3048    
3049            /**
3050             * Finds the first layout in the ordered set where groupId = &#63; and privateLayout = &#63; and parentLayoutId = &#63;.
3051             *
3052             * <p>
3053             * 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.
3054             * </p>
3055             *
3056             * @param groupId the group id to search with
3057             * @param privateLayout the private layout to search with
3058             * @param parentLayoutId the parent layout id to search with
3059             * @param orderByComparator the comparator to order the set by
3060             * @return the first matching layout
3061             * @throws com.liferay.portal.NoSuchLayoutException if a matching layout could not be found
3062             * @throws SystemException if a system exception occurred
3063             */
3064            public Layout findByG_P_P_First(long groupId, boolean privateLayout,
3065                    long parentLayoutId, OrderByComparator orderByComparator)
3066                    throws NoSuchLayoutException, SystemException {
3067                    List<Layout> list = findByG_P_P(groupId, privateLayout, parentLayoutId,
3068                                    0, 1, orderByComparator);
3069    
3070                    if (list.isEmpty()) {
3071                            StringBundler msg = new StringBundler(8);
3072    
3073                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3074    
3075                            msg.append("groupId=");
3076                            msg.append(groupId);
3077    
3078                            msg.append(", privateLayout=");
3079                            msg.append(privateLayout);
3080    
3081                            msg.append(", parentLayoutId=");
3082                            msg.append(parentLayoutId);
3083    
3084                            msg.append(StringPool.CLOSE_CURLY_BRACE);
3085    
3086                            throw new NoSuchLayoutException(msg.toString());
3087                    }
3088                    else {
3089                            return list.get(0);
3090                    }
3091            }
3092    
3093            /**
3094             * Finds the last layout in the ordered set where groupId = &#63; and privateLayout = &#63; and parentLayoutId = &#63;.
3095             *
3096             * <p>
3097             * 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.
3098             * </p>
3099             *
3100             * @param groupId the group id to search with
3101             * @param privateLayout the private layout to search with
3102             * @param parentLayoutId the parent layout id to search with
3103             * @param orderByComparator the comparator to order the set by
3104             * @return the last matching layout
3105             * @throws com.liferay.portal.NoSuchLayoutException if a matching layout could not be found
3106             * @throws SystemException if a system exception occurred
3107             */
3108            public Layout findByG_P_P_Last(long groupId, boolean privateLayout,
3109                    long parentLayoutId, OrderByComparator orderByComparator)
3110                    throws NoSuchLayoutException, SystemException {
3111                    int count = countByG_P_P(groupId, privateLayout, parentLayoutId);
3112    
3113                    List<Layout> list = findByG_P_P(groupId, privateLayout, parentLayoutId,
3114                                    count - 1, count, orderByComparator);
3115    
3116                    if (list.isEmpty()) {
3117                            StringBundler msg = new StringBundler(8);
3118    
3119                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3120    
3121                            msg.append("groupId=");
3122                            msg.append(groupId);
3123    
3124                            msg.append(", privateLayout=");
3125                            msg.append(privateLayout);
3126    
3127                            msg.append(", parentLayoutId=");
3128                            msg.append(parentLayoutId);
3129    
3130                            msg.append(StringPool.CLOSE_CURLY_BRACE);
3131    
3132                            throw new NoSuchLayoutException(msg.toString());
3133                    }
3134                    else {
3135                            return list.get(0);
3136                    }
3137            }
3138    
3139            /**
3140             * Finds the layouts before and after the current layout in the ordered set where groupId = &#63; and privateLayout = &#63; and parentLayoutId = &#63;.
3141             *
3142             * <p>
3143             * 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.
3144             * </p>
3145             *
3146             * @param plid the primary key of the current layout
3147             * @param groupId the group id to search with
3148             * @param privateLayout the private layout to search with
3149             * @param parentLayoutId the parent layout id to search with
3150             * @param orderByComparator the comparator to order the set by
3151             * @return the previous, current, and next layout
3152             * @throws com.liferay.portal.NoSuchLayoutException if a layout with the primary key could not be found
3153             * @throws SystemException if a system exception occurred
3154             */
3155            public Layout[] findByG_P_P_PrevAndNext(long plid, long groupId,
3156                    boolean privateLayout, long parentLayoutId,
3157                    OrderByComparator orderByComparator)
3158                    throws NoSuchLayoutException, SystemException {
3159                    Layout layout = findByPrimaryKey(plid);
3160    
3161                    Session session = null;
3162    
3163                    try {
3164                            session = openSession();
3165    
3166                            Layout[] array = new LayoutImpl[3];
3167    
3168                            array[0] = getByG_P_P_PrevAndNext(session, layout, groupId,
3169                                            privateLayout, parentLayoutId, orderByComparator, true);
3170    
3171                            array[1] = layout;
3172    
3173                            array[2] = getByG_P_P_PrevAndNext(session, layout, groupId,
3174                                            privateLayout, parentLayoutId, orderByComparator, false);
3175    
3176                            return array;
3177                    }
3178                    catch (Exception e) {
3179                            throw processException(e);
3180                    }
3181                    finally {
3182                            closeSession(session);
3183                    }
3184            }
3185    
3186            protected Layout getByG_P_P_PrevAndNext(Session session, Layout layout,
3187                    long groupId, boolean privateLayout, long parentLayoutId,
3188                    OrderByComparator orderByComparator, boolean previous) {
3189                    StringBundler query = null;
3190    
3191                    if (orderByComparator != null) {
3192                            query = new StringBundler(6 +
3193                                            (orderByComparator.getOrderByFields().length * 6));
3194                    }
3195                    else {
3196                            query = new StringBundler(3);
3197                    }
3198    
3199                    query.append(_SQL_SELECT_LAYOUT_WHERE);
3200    
3201                    query.append(_FINDER_COLUMN_G_P_P_GROUPID_2);
3202    
3203                    query.append(_FINDER_COLUMN_G_P_P_PRIVATELAYOUT_2);
3204    
3205                    query.append(_FINDER_COLUMN_G_P_P_PARENTLAYOUTID_2);
3206    
3207                    if (orderByComparator != null) {
3208                            String[] orderByFields = orderByComparator.getOrderByFields();
3209    
3210                            if (orderByFields.length > 0) {
3211                                    query.append(WHERE_AND);
3212                            }
3213    
3214                            for (int i = 0; i < orderByFields.length; i++) {
3215                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3216                                    query.append(orderByFields[i]);
3217    
3218                                    if ((i + 1) < orderByFields.length) {
3219                                            if (orderByComparator.isAscending() ^ previous) {
3220                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3221                                            }
3222                                            else {
3223                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3224                                            }
3225                                    }
3226                                    else {
3227                                            if (orderByComparator.isAscending() ^ previous) {
3228                                                    query.append(WHERE_GREATER_THAN);
3229                                            }
3230                                            else {
3231                                                    query.append(WHERE_LESSER_THAN);
3232                                            }
3233                                    }
3234                            }
3235    
3236                            query.append(ORDER_BY_CLAUSE);
3237    
3238                            for (int i = 0; i < orderByFields.length; i++) {
3239                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3240                                    query.append(orderByFields[i]);
3241    
3242                                    if ((i + 1) < orderByFields.length) {
3243                                            if (orderByComparator.isAscending() ^ previous) {
3244                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3245                                            }
3246                                            else {
3247                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3248                                            }
3249                                    }
3250                                    else {
3251                                            if (orderByComparator.isAscending() ^ previous) {
3252                                                    query.append(ORDER_BY_ASC);
3253                                            }
3254                                            else {
3255                                                    query.append(ORDER_BY_DESC);
3256                                            }
3257                                    }
3258                            }
3259                    }
3260    
3261                    else {
3262                            query.append(LayoutModelImpl.ORDER_BY_JPQL);
3263                    }
3264    
3265                    String sql = query.toString();
3266    
3267                    Query q = session.createQuery(sql);
3268    
3269                    q.setFirstResult(0);
3270                    q.setMaxResults(2);
3271    
3272                    QueryPos qPos = QueryPos.getInstance(q);
3273    
3274                    qPos.add(groupId);
3275    
3276                    qPos.add(privateLayout);
3277    
3278                    qPos.add(parentLayoutId);
3279    
3280                    if (orderByComparator != null) {
3281                            Object[] values = orderByComparator.getOrderByValues(layout);
3282    
3283                            for (Object value : values) {
3284                                    qPos.add(value);
3285                            }
3286                    }
3287    
3288                    List<Layout> list = q.list();
3289    
3290                    if (list.size() == 2) {
3291                            return list.get(1);
3292                    }
3293                    else {
3294                            return null;
3295                    }
3296            }
3297    
3298            /**
3299             * Filters by the user's permissions and finds all the layouts where groupId = &#63; and privateLayout = &#63; and parentLayoutId = &#63;.
3300             *
3301             * @param groupId the group id to search with
3302             * @param privateLayout the private layout to search with
3303             * @param parentLayoutId the parent layout id to search with
3304             * @return the matching layouts that the user has permission to view
3305             * @throws SystemException if a system exception occurred
3306             */
3307            public List<Layout> filterFindByG_P_P(long groupId, boolean privateLayout,
3308                    long parentLayoutId) throws SystemException {
3309                    return filterFindByG_P_P(groupId, privateLayout, parentLayoutId,
3310                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3311            }
3312    
3313            /**
3314             * Filters by the user's permissions and finds a range of all the layouts where groupId = &#63; and privateLayout = &#63; and parentLayoutId = &#63;.
3315             *
3316             * <p>
3317             * 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.
3318             * </p>
3319             *
3320             * @param groupId the group id to search with
3321             * @param privateLayout the private layout to search with
3322             * @param parentLayoutId the parent layout id to search with
3323             * @param start the lower bound of the range of layouts to return
3324             * @param end the upper bound of the range of layouts to return (not inclusive)
3325             * @return the range of matching layouts that the user has permission to view
3326             * @throws SystemException if a system exception occurred
3327             */
3328            public List<Layout> filterFindByG_P_P(long groupId, boolean privateLayout,
3329                    long parentLayoutId, int start, int end) throws SystemException {
3330                    return filterFindByG_P_P(groupId, privateLayout, parentLayoutId, start,
3331                            end, null);
3332            }
3333    
3334            /**
3335             * Filters by the user's permissions and finds an ordered range of all the layouts where groupId = &#63; and privateLayout = &#63; and parentLayoutId = &#63;.
3336             *
3337             * <p>
3338             * 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.
3339             * </p>
3340             *
3341             * @param groupId the group id to search with
3342             * @param privateLayout the private layout to search with
3343             * @param parentLayoutId the parent layout id to search with
3344             * @param start the lower bound of the range of layouts to return
3345             * @param end the upper bound of the range of layouts to return (not inclusive)
3346             * @param orderByComparator the comparator to order the results by
3347             * @return the ordered range of matching layouts that the user has permission to view
3348             * @throws SystemException if a system exception occurred
3349             */
3350            public List<Layout> filterFindByG_P_P(long groupId, boolean privateLayout,
3351                    long parentLayoutId, int start, int end,
3352                    OrderByComparator orderByComparator) throws SystemException {
3353                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3354                            return findByG_P_P(groupId, privateLayout, parentLayoutId, start,
3355                                    end, orderByComparator);
3356                    }
3357    
3358                    StringBundler query = null;
3359    
3360                    if (orderByComparator != null) {
3361                            query = new StringBundler(5 +
3362                                            (orderByComparator.getOrderByFields().length * 3));
3363                    }
3364                    else {
3365                            query = new StringBundler(5);
3366                    }
3367    
3368                    if (getDB().isSupportsInlineDistinct()) {
3369                            query.append(_FILTER_SQL_SELECT_LAYOUT_WHERE);
3370                    }
3371                    else {
3372                            query.append(_FILTER_SQL_SELECT_LAYOUT_NO_INLINE_DISTINCT_WHERE_1);
3373                    }
3374    
3375                    query.append(_FINDER_COLUMN_G_P_P_GROUPID_2);
3376    
3377                    query.append(_FINDER_COLUMN_G_P_P_PRIVATELAYOUT_2);
3378    
3379                    query.append(_FINDER_COLUMN_G_P_P_PARENTLAYOUTID_2);
3380    
3381                    if (!getDB().isSupportsInlineDistinct()) {
3382                            query.append(_FILTER_SQL_SELECT_LAYOUT_NO_INLINE_DISTINCT_WHERE_2);
3383                    }
3384    
3385                    if (orderByComparator != null) {
3386                            if (getDB().isSupportsInlineDistinct()) {
3387                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3388                                            orderByComparator);
3389                            }
3390                            else {
3391                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3392                                            orderByComparator);
3393                            }
3394                    }
3395    
3396                    else {
3397                            if (getDB().isSupportsInlineDistinct()) {
3398                                    query.append(LayoutModelImpl.ORDER_BY_JPQL);
3399                            }
3400                            else {
3401                                    query.append(LayoutModelImpl.ORDER_BY_SQL);
3402                            }
3403                    }
3404    
3405                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3406                                    Layout.class.getName(), _FILTER_COLUMN_PK,
3407                                    _FILTER_COLUMN_USERID, groupId);
3408    
3409                    Session session = null;
3410    
3411                    try {
3412                            session = openSession();
3413    
3414                            SQLQuery q = session.createSQLQuery(sql);
3415    
3416                            if (getDB().isSupportsInlineDistinct()) {
3417                                    q.addEntity(_FILTER_ENTITY_ALIAS, LayoutImpl.class);
3418                            }
3419                            else {
3420                                    q.addEntity(_FILTER_ENTITY_TABLE, LayoutImpl.class);
3421                            }
3422    
3423                            QueryPos qPos = QueryPos.getInstance(q);
3424    
3425                            qPos.add(groupId);
3426    
3427                            qPos.add(privateLayout);
3428    
3429                            qPos.add(parentLayoutId);
3430    
3431                            return (List<Layout>)QueryUtil.list(q, getDialect(), start, end);
3432                    }
3433                    catch (Exception e) {
3434                            throw processException(e);
3435                    }
3436                    finally {
3437                            closeSession(session);
3438                    }
3439            }
3440    
3441            /**
3442             * Finds 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.
3443             *
3444             * @param groupId the group id to search with
3445             * @param privateLayout the private layout to search with
3446             * @param friendlyURL the friendly u r l to search with
3447             * @return the matching layout
3448             * @throws com.liferay.portal.NoSuchLayoutException if a matching layout could not be found
3449             * @throws SystemException if a system exception occurred
3450             */
3451            public Layout findByG_P_F(long groupId, boolean privateLayout,
3452                    String friendlyURL) throws NoSuchLayoutException, SystemException {
3453                    Layout layout = fetchByG_P_F(groupId, privateLayout, friendlyURL);
3454    
3455                    if (layout == null) {
3456                            StringBundler msg = new StringBundler(8);
3457    
3458                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3459    
3460                            msg.append("groupId=");
3461                            msg.append(groupId);
3462    
3463                            msg.append(", privateLayout=");
3464                            msg.append(privateLayout);
3465    
3466                            msg.append(", friendlyURL=");
3467                            msg.append(friendlyURL);
3468    
3469                            msg.append(StringPool.CLOSE_CURLY_BRACE);
3470    
3471                            if (_log.isWarnEnabled()) {
3472                                    _log.warn(msg.toString());
3473                            }
3474    
3475                            throw new NoSuchLayoutException(msg.toString());
3476                    }
3477    
3478                    return layout;
3479            }
3480    
3481            /**
3482             * Finds 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.
3483             *
3484             * @param groupId the group id to search with
3485             * @param privateLayout the private layout to search with
3486             * @param friendlyURL the friendly u r l to search with
3487             * @return the matching layout, or <code>null</code> if a matching layout could not be found
3488             * @throws SystemException if a system exception occurred
3489             */
3490            public Layout fetchByG_P_F(long groupId, boolean privateLayout,
3491                    String friendlyURL) throws SystemException {
3492                    return fetchByG_P_F(groupId, privateLayout, friendlyURL, true);
3493            }
3494    
3495            /**
3496             * Finds 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.
3497             *
3498             * @param groupId the group id to search with
3499             * @param privateLayout the private layout to search with
3500             * @param friendlyURL the friendly u r l to search with
3501             * @return the matching layout, or <code>null</code> if a matching layout could not be found
3502             * @throws SystemException if a system exception occurred
3503             */
3504            public Layout fetchByG_P_F(long groupId, boolean privateLayout,
3505                    String friendlyURL, boolean retrieveFromCache)
3506                    throws SystemException {
3507                    Object[] finderArgs = new Object[] { groupId, privateLayout, friendlyURL };
3508    
3509                    Object result = null;
3510    
3511                    if (retrieveFromCache) {
3512                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_P_F,
3513                                            finderArgs, this);
3514                    }
3515    
3516                    if (result == null) {
3517                            StringBundler query = new StringBundler(5);
3518    
3519                            query.append(_SQL_SELECT_LAYOUT_WHERE);
3520    
3521                            query.append(_FINDER_COLUMN_G_P_F_GROUPID_2);
3522    
3523                            query.append(_FINDER_COLUMN_G_P_F_PRIVATELAYOUT_2);
3524    
3525                            if (friendlyURL == null) {
3526                                    query.append(_FINDER_COLUMN_G_P_F_FRIENDLYURL_1);
3527                            }
3528                            else {
3529                                    if (friendlyURL.equals(StringPool.BLANK)) {
3530                                            query.append(_FINDER_COLUMN_G_P_F_FRIENDLYURL_3);
3531                                    }
3532                                    else {
3533                                            query.append(_FINDER_COLUMN_G_P_F_FRIENDLYURL_2);
3534                                    }
3535                            }
3536    
3537                            query.append(LayoutModelImpl.ORDER_BY_JPQL);
3538    
3539                            String sql = query.toString();
3540    
3541                            Session session = null;
3542    
3543                            try {
3544                                    session = openSession();
3545    
3546                                    Query q = session.createQuery(sql);
3547    
3548                                    QueryPos qPos = QueryPos.getInstance(q);
3549    
3550                                    qPos.add(groupId);
3551    
3552                                    qPos.add(privateLayout);
3553    
3554                                    if (friendlyURL != null) {
3555                                            qPos.add(friendlyURL);
3556                                    }
3557    
3558                                    List<Layout> list = q.list();
3559    
3560                                    result = list;
3561    
3562                                    Layout layout = null;
3563    
3564                                    if (list.isEmpty()) {
3565                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_F,
3566                                                    finderArgs, list);
3567                                    }
3568                                    else {
3569                                            layout = list.get(0);
3570    
3571                                            cacheResult(layout);
3572    
3573                                            if ((layout.getGroupId() != groupId) ||
3574                                                            (layout.getPrivateLayout() != privateLayout) ||
3575                                                            (layout.getFriendlyURL() == null) ||
3576                                                            !layout.getFriendlyURL().equals(friendlyURL)) {
3577                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_F,
3578                                                            finderArgs, layout);
3579                                            }
3580                                    }
3581    
3582                                    return layout;
3583                            }
3584                            catch (Exception e) {
3585                                    throw processException(e);
3586                            }
3587                            finally {
3588                                    if (result == null) {
3589                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P_F,
3590                                                    finderArgs);
3591                                    }
3592    
3593                                    closeSession(session);
3594                            }
3595                    }
3596                    else {
3597                            if (result instanceof List<?>) {
3598                                    return null;
3599                            }
3600                            else {
3601                                    return (Layout)result;
3602                            }
3603                    }
3604            }
3605    
3606            /**
3607             * Finds all the layouts where groupId = &#63; and privateLayout = &#63; and type = &#63;.
3608             *
3609             * @param groupId the group id to search with
3610             * @param privateLayout the private layout to search with
3611             * @param type the type to search with
3612             * @return the matching layouts
3613             * @throws SystemException if a system exception occurred
3614             */
3615            public List<Layout> findByG_P_T(long groupId, boolean privateLayout,
3616                    String type) throws SystemException {
3617                    return findByG_P_T(groupId, privateLayout, type, QueryUtil.ALL_POS,
3618                            QueryUtil.ALL_POS, null);
3619            }
3620    
3621            /**
3622             * Finds a range of all the layouts where groupId = &#63; and privateLayout = &#63; and type = &#63;.
3623             *
3624             * <p>
3625             * 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.
3626             * </p>
3627             *
3628             * @param groupId the group id to search with
3629             * @param privateLayout the private layout to search with
3630             * @param type the type to search with
3631             * @param start the lower bound of the range of layouts to return
3632             * @param end the upper bound of the range of layouts to return (not inclusive)
3633             * @return the range of matching layouts
3634             * @throws SystemException if a system exception occurred
3635             */
3636            public List<Layout> findByG_P_T(long groupId, boolean privateLayout,
3637                    String type, int start, int end) throws SystemException {
3638                    return findByG_P_T(groupId, privateLayout, type, start, end, null);
3639            }
3640    
3641            /**
3642             * Finds an ordered range of all the layouts where groupId = &#63; and privateLayout = &#63; and type = &#63;.
3643             *
3644             * <p>
3645             * 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.
3646             * </p>
3647             *
3648             * @param groupId the group id to search with
3649             * @param privateLayout the private layout to search with
3650             * @param type the type to search with
3651             * @param start the lower bound of the range of layouts to return
3652             * @param end the upper bound of the range of layouts to return (not inclusive)
3653             * @param orderByComparator the comparator to order the results by
3654             * @return the ordered range of matching layouts
3655             * @throws SystemException if a system exception occurred
3656             */
3657            public List<Layout> findByG_P_T(long groupId, boolean privateLayout,
3658                    String type, int start, int end, OrderByComparator orderByComparator)
3659                    throws SystemException {
3660                    Object[] finderArgs = new Object[] {
3661                                    groupId, privateLayout, type,
3662                                    
3663                                    String.valueOf(start), String.valueOf(end),
3664                                    String.valueOf(orderByComparator)
3665                            };
3666    
3667                    List<Layout> list = (List<Layout>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_P_T,
3668                                    finderArgs, this);
3669    
3670                    if (list == null) {
3671                            StringBundler query = null;
3672    
3673                            if (orderByComparator != null) {
3674                                    query = new StringBundler(5 +
3675                                                    (orderByComparator.getOrderByFields().length * 3));
3676                            }
3677                            else {
3678                                    query = new StringBundler(5);
3679                            }
3680    
3681                            query.append(_SQL_SELECT_LAYOUT_WHERE);
3682    
3683                            query.append(_FINDER_COLUMN_G_P_T_GROUPID_2);
3684    
3685                            query.append(_FINDER_COLUMN_G_P_T_PRIVATELAYOUT_2);
3686    
3687                            if (type == null) {
3688                                    query.append(_FINDER_COLUMN_G_P_T_TYPE_1);
3689                            }
3690                            else {
3691                                    if (type.equals(StringPool.BLANK)) {
3692                                            query.append(_FINDER_COLUMN_G_P_T_TYPE_3);
3693                                    }
3694                                    else {
3695                                            query.append(_FINDER_COLUMN_G_P_T_TYPE_2);
3696                                    }
3697                            }
3698    
3699                            if (orderByComparator != null) {
3700                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3701                                            orderByComparator);
3702                            }
3703    
3704                            else {
3705                                    query.append(LayoutModelImpl.ORDER_BY_JPQL);
3706                            }
3707    
3708                            String sql = query.toString();
3709    
3710                            Session session = null;
3711    
3712                            try {
3713                                    session = openSession();
3714    
3715                                    Query q = session.createQuery(sql);
3716    
3717                                    QueryPos qPos = QueryPos.getInstance(q);
3718    
3719                                    qPos.add(groupId);
3720    
3721                                    qPos.add(privateLayout);
3722    
3723                                    if (type != null) {
3724                                            qPos.add(type);
3725                                    }
3726    
3727                                    list = (List<Layout>)QueryUtil.list(q, getDialect(), start, end);
3728                            }
3729                            catch (Exception e) {
3730                                    throw processException(e);
3731                            }
3732                            finally {
3733                                    if (list == null) {
3734                                            FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_G_P_T,
3735                                                    finderArgs);
3736                                    }
3737                                    else {
3738                                            cacheResult(list);
3739    
3740                                            FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_P_T,
3741                                                    finderArgs, list);
3742                                    }
3743    
3744                                    closeSession(session);
3745                            }
3746                    }
3747    
3748                    return list;
3749            }
3750    
3751            /**
3752             * Finds the first layout in the ordered set where groupId = &#63; and privateLayout = &#63; and type = &#63;.
3753             *
3754             * <p>
3755             * 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.
3756             * </p>
3757             *
3758             * @param groupId the group id to search with
3759             * @param privateLayout the private layout to search with
3760             * @param type the type to search with
3761             * @param orderByComparator the comparator to order the set by
3762             * @return the first matching layout
3763             * @throws com.liferay.portal.NoSuchLayoutException if a matching layout could not be found
3764             * @throws SystemException if a system exception occurred
3765             */
3766            public Layout findByG_P_T_First(long groupId, boolean privateLayout,
3767                    String type, OrderByComparator orderByComparator)
3768                    throws NoSuchLayoutException, SystemException {
3769                    List<Layout> list = findByG_P_T(groupId, privateLayout, type, 0, 1,
3770                                    orderByComparator);
3771    
3772                    if (list.isEmpty()) {
3773                            StringBundler msg = new StringBundler(8);
3774    
3775                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3776    
3777                            msg.append("groupId=");
3778                            msg.append(groupId);
3779    
3780                            msg.append(", privateLayout=");
3781                            msg.append(privateLayout);
3782    
3783                            msg.append(", type=");
3784                            msg.append(type);
3785    
3786                            msg.append(StringPool.CLOSE_CURLY_BRACE);
3787    
3788                            throw new NoSuchLayoutException(msg.toString());
3789                    }
3790                    else {
3791                            return list.get(0);
3792                    }
3793            }
3794    
3795            /**
3796             * Finds the last layout in the ordered set where groupId = &#63; and privateLayout = &#63; and type = &#63;.
3797             *
3798             * <p>
3799             * 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.
3800             * </p>
3801             *
3802             * @param groupId the group id to search with
3803             * @param privateLayout the private layout to search with
3804             * @param type the type to search with
3805             * @param orderByComparator the comparator to order the set by
3806             * @return the last matching layout
3807             * @throws com.liferay.portal.NoSuchLayoutException if a matching layout could not be found
3808             * @throws SystemException if a system exception occurred
3809             */
3810            public Layout findByG_P_T_Last(long groupId, boolean privateLayout,
3811                    String type, OrderByComparator orderByComparator)
3812                    throws NoSuchLayoutException, SystemException {
3813                    int count = countByG_P_T(groupId, privateLayout, type);
3814    
3815                    List<Layout> list = findByG_P_T(groupId, privateLayout, type,
3816                                    count - 1, count, orderByComparator);
3817    
3818                    if (list.isEmpty()) {
3819                            StringBundler msg = new StringBundler(8);
3820    
3821                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3822    
3823                            msg.append("groupId=");
3824                            msg.append(groupId);
3825    
3826                            msg.append(", privateLayout=");
3827                            msg.append(privateLayout);
3828    
3829                            msg.append(", type=");
3830                            msg.append(type);
3831    
3832                            msg.append(StringPool.CLOSE_CURLY_BRACE);
3833    
3834                            throw new NoSuchLayoutException(msg.toString());
3835                    }
3836                    else {
3837                            return list.get(0);
3838                    }
3839            }
3840    
3841            /**
3842             * Finds the layouts before and after the current layout in the ordered set where groupId = &#63; and privateLayout = &#63; and type = &#63;.
3843             *
3844             * <p>
3845             * 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.
3846             * </p>
3847             *
3848             * @param plid the primary key of the current layout
3849             * @param groupId the group id to search with
3850             * @param privateLayout the private layout to search with
3851             * @param type the type to search with
3852             * @param orderByComparator the comparator to order the set by
3853             * @return the previous, current, and next layout
3854             * @throws com.liferay.portal.NoSuchLayoutException if a layout with the primary key could not be found
3855             * @throws SystemException if a system exception occurred
3856             */
3857            public Layout[] findByG_P_T_PrevAndNext(long plid, long groupId,
3858                    boolean privateLayout, String type, OrderByComparator orderByComparator)
3859                    throws NoSuchLayoutException, SystemException {
3860                    Layout layout = findByPrimaryKey(plid);
3861    
3862                    Session session = null;
3863    
3864                    try {
3865                            session = openSession();
3866    
3867                            Layout[] array = new LayoutImpl[3];
3868    
3869                            array[0] = getByG_P_T_PrevAndNext(session, layout, groupId,
3870                                            privateLayout, type, orderByComparator, true);
3871    
3872                            array[1] = layout;
3873    
3874                            array[2] = getByG_P_T_PrevAndNext(session, layout, groupId,
3875                                            privateLayout, type, orderByComparator, false);
3876    
3877                            return array;
3878                    }
3879                    catch (Exception e) {
3880                            throw processException(e);
3881                    }
3882                    finally {
3883                            closeSession(session);
3884                    }
3885            }
3886    
3887            protected Layout getByG_P_T_PrevAndNext(Session session, Layout layout,
3888                    long groupId, boolean privateLayout, String type,
3889                    OrderByComparator orderByComparator, boolean previous) {
3890                    StringBundler query = null;
3891    
3892                    if (orderByComparator != null) {
3893                            query = new StringBundler(6 +
3894                                            (orderByComparator.getOrderByFields().length * 6));
3895                    }
3896                    else {
3897                            query = new StringBundler(3);
3898                    }
3899    
3900                    query.append(_SQL_SELECT_LAYOUT_WHERE);
3901    
3902                    query.append(_FINDER_COLUMN_G_P_T_GROUPID_2);
3903    
3904                    query.append(_FINDER_COLUMN_G_P_T_PRIVATELAYOUT_2);
3905    
3906                    if (type == null) {
3907                            query.append(_FINDER_COLUMN_G_P_T_TYPE_1);
3908                    }
3909                    else {
3910                            if (type.equals(StringPool.BLANK)) {
3911                                    query.append(_FINDER_COLUMN_G_P_T_TYPE_3);
3912                            }
3913                            else {
3914                                    query.append(_FINDER_COLUMN_G_P_T_TYPE_2);
3915                            }
3916                    }
3917    
3918                    if (orderByComparator != null) {
3919                            String[] orderByFields = orderByComparator.getOrderByFields();
3920    
3921                            if (orderByFields.length > 0) {
3922                                    query.append(WHERE_AND);
3923                            }
3924    
3925                            for (int i = 0; i < orderByFields.length; i++) {
3926                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3927                                    query.append(orderByFields[i]);
3928    
3929                                    if ((i + 1) < orderByFields.length) {
3930                                            if (orderByComparator.isAscending() ^ previous) {
3931                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3932                                            }
3933                                            else {
3934                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3935                                            }
3936                                    }
3937                                    else {
3938                                            if (orderByComparator.isAscending() ^ previous) {
3939                                                    query.append(WHERE_GREATER_THAN);
3940                                            }
3941                                            else {
3942                                                    query.append(WHERE_LESSER_THAN);
3943                                            }
3944                                    }
3945                            }
3946    
3947                            query.append(ORDER_BY_CLAUSE);
3948    
3949                            for (int i = 0; i < orderByFields.length; i++) {
3950                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3951                                    query.append(orderByFields[i]);
3952    
3953                                    if ((i + 1) < orderByFields.length) {
3954                                            if (orderByComparator.isAscending() ^ previous) {
3955                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3956                                            }
3957                                            else {
3958                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3959                                            }
3960                                    }
3961                                    else {
3962                                            if (orderByComparator.isAscending() ^ previous) {
3963                                                    query.append(ORDER_BY_ASC);
3964                                            }
3965                                            else {
3966                                                    query.append(ORDER_BY_DESC);
3967                                            }
3968                                    }
3969                            }
3970                    }
3971    
3972                    else {
3973                            query.append(LayoutModelImpl.ORDER_BY_JPQL);
3974                    }
3975    
3976                    String sql = query.toString();
3977    
3978                    Query q = session.createQuery(sql);
3979    
3980                    q.setFirstResult(0);
3981                    q.setMaxResults(2);
3982    
3983                    QueryPos qPos = QueryPos.getInstance(q);
3984    
3985                    qPos.add(groupId);
3986    
3987                    qPos.add(privateLayout);
3988    
3989                    if (type != null) {
3990                            qPos.add(type);
3991                    }
3992    
3993                    if (orderByComparator != null) {
3994                            Object[] values = orderByComparator.getOrderByValues(layout);
3995    
3996                            for (Object value : values) {
3997                                    qPos.add(value);
3998                            }
3999                    }
4000    
4001                    List<Layout> list = q.list();
4002    
4003                    if (list.size() == 2) {
4004                            return list.get(1);
4005                    }
4006                    else {
4007                            return null;
4008                    }
4009            }
4010    
4011            /**
4012             * Filters by the user's permissions and finds all the layouts where groupId = &#63; and privateLayout = &#63; and type = &#63;.
4013             *
4014             * @param groupId the group id to search with
4015             * @param privateLayout the private layout to search with
4016             * @param type the type to search with
4017             * @return the matching layouts that the user has permission to view
4018             * @throws SystemException if a system exception occurred
4019             */
4020            public List<Layout> filterFindByG_P_T(long groupId, boolean privateLayout,
4021                    String type) throws SystemException {
4022                    return filterFindByG_P_T(groupId, privateLayout, type,
4023                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
4024            }
4025    
4026            /**
4027             * Filters by the user's permissions and finds a range of all the layouts where groupId = &#63; and privateLayout = &#63; and type = &#63;.
4028             *
4029             * <p>
4030             * 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.
4031             * </p>
4032             *
4033             * @param groupId the group id to search with
4034             * @param privateLayout the private layout to search with
4035             * @param type the type to search with
4036             * @param start the lower bound of the range of layouts to return
4037             * @param end the upper bound of the range of layouts to return (not inclusive)
4038             * @return the range of matching layouts that the user has permission to view
4039             * @throws SystemException if a system exception occurred
4040             */
4041            public List<Layout> filterFindByG_P_T(long groupId, boolean privateLayout,
4042                    String type, int start, int end) throws SystemException {
4043                    return filterFindByG_P_T(groupId, privateLayout, type, start, end, null);
4044            }
4045    
4046            /**
4047             * Filters by the user's permissions and finds an ordered range of all the layouts where groupId = &#63; and privateLayout = &#63; and type = &#63;.
4048             *
4049             * <p>
4050             * 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.
4051             * </p>
4052             *
4053             * @param groupId the group id to search with
4054             * @param privateLayout the private layout to search with
4055             * @param type the type to search with
4056             * @param start the lower bound of the range of layouts to return
4057             * @param end the upper bound of the range of layouts to return (not inclusive)
4058             * @param orderByComparator the comparator to order the results by
4059             * @return the ordered range of matching layouts that the user has permission to view
4060             * @throws SystemException if a system exception occurred
4061             */
4062            public List<Layout> filterFindByG_P_T(long groupId, boolean privateLayout,
4063                    String type, int start, int end, OrderByComparator orderByComparator)
4064                    throws SystemException {
4065                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4066                            return findByG_P_T(groupId, privateLayout, type, start, end,
4067                                    orderByComparator);
4068                    }
4069    
4070                    StringBundler query = null;
4071    
4072                    if (orderByComparator != null) {
4073                            query = new StringBundler(5 +
4074                                            (orderByComparator.getOrderByFields().length * 3));
4075                    }
4076                    else {
4077                            query = new StringBundler(5);
4078                    }
4079    
4080                    if (getDB().isSupportsInlineDistinct()) {
4081                            query.append(_FILTER_SQL_SELECT_LAYOUT_WHERE);
4082                    }
4083                    else {
4084                            query.append(_FILTER_SQL_SELECT_LAYOUT_NO_INLINE_DISTINCT_WHERE_1);
4085                    }
4086    
4087                    query.append(_FINDER_COLUMN_G_P_T_GROUPID_2);
4088    
4089                    query.append(_FINDER_COLUMN_G_P_T_PRIVATELAYOUT_2);
4090    
4091                    if (type == null) {
4092                            query.append(_FINDER_COLUMN_G_P_T_TYPE_1);
4093                    }
4094                    else {
4095                            if (type.equals(StringPool.BLANK)) {
4096                                    query.append(_FINDER_COLUMN_G_P_T_TYPE_3);
4097                            }
4098                            else {
4099                                    query.append(_FINDER_COLUMN_G_P_T_TYPE_2);
4100                            }
4101                    }
4102    
4103                    if (!getDB().isSupportsInlineDistinct()) {
4104                            query.append(_FILTER_SQL_SELECT_LAYOUT_NO_INLINE_DISTINCT_WHERE_2);
4105                    }
4106    
4107                    if (orderByComparator != null) {
4108                            if (getDB().isSupportsInlineDistinct()) {
4109                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4110                                            orderByComparator);
4111                            }
4112                            else {
4113                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
4114                                            orderByComparator);
4115                            }
4116                    }
4117    
4118                    else {
4119                            if (getDB().isSupportsInlineDistinct()) {
4120                                    query.append(LayoutModelImpl.ORDER_BY_JPQL);
4121                            }
4122                            else {
4123                                    query.append(LayoutModelImpl.ORDER_BY_SQL);
4124                            }
4125                    }
4126    
4127                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4128                                    Layout.class.getName(), _FILTER_COLUMN_PK,
4129                                    _FILTER_COLUMN_USERID, groupId);
4130    
4131                    Session session = null;
4132    
4133                    try {
4134                            session = openSession();
4135    
4136                            SQLQuery q = session.createSQLQuery(sql);
4137    
4138                            if (getDB().isSupportsInlineDistinct()) {
4139                                    q.addEntity(_FILTER_ENTITY_ALIAS, LayoutImpl.class);
4140                            }
4141                            else {
4142                                    q.addEntity(_FILTER_ENTITY_TABLE, LayoutImpl.class);
4143                            }
4144    
4145                            QueryPos qPos = QueryPos.getInstance(q);
4146    
4147                            qPos.add(groupId);
4148    
4149                            qPos.add(privateLayout);
4150    
4151                            if (type != null) {
4152                                    qPos.add(type);
4153                            }
4154    
4155                            return (List<Layout>)QueryUtil.list(q, getDialect(), start, end);
4156                    }
4157                    catch (Exception e) {
4158                            throw processException(e);
4159                    }
4160                    finally {
4161                            closeSession(session);
4162                    }
4163            }
4164    
4165            /**
4166             * Finds all the layouts.
4167             *
4168             * @return the layouts
4169             * @throws SystemException if a system exception occurred
4170             */
4171            public List<Layout> findAll() throws SystemException {
4172                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
4173            }
4174    
4175            /**
4176             * Finds a range of all the layouts.
4177             *
4178             * <p>
4179             * 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.
4180             * </p>
4181             *
4182             * @param start the lower bound of the range of layouts to return
4183             * @param end the upper bound of the range of layouts to return (not inclusive)
4184             * @return the range of layouts
4185             * @throws SystemException if a system exception occurred
4186             */
4187            public List<Layout> findAll(int start, int end) throws SystemException {
4188                    return findAll(start, end, null);
4189            }
4190    
4191            /**
4192             * Finds an ordered range of all the layouts.
4193             *
4194             * <p>
4195             * 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.
4196             * </p>
4197             *
4198             * @param start the lower bound of the range of layouts to return
4199             * @param end the upper bound of the range of layouts to return (not inclusive)
4200             * @param orderByComparator the comparator to order the results by
4201             * @return the ordered range of layouts
4202             * @throws SystemException if a system exception occurred
4203             */
4204            public List<Layout> findAll(int start, int end,
4205                    OrderByComparator orderByComparator) throws SystemException {
4206                    Object[] finderArgs = new Object[] {
4207                                    String.valueOf(start), String.valueOf(end),
4208                                    String.valueOf(orderByComparator)
4209                            };
4210    
4211                    List<Layout> list = (List<Layout>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
4212                                    finderArgs, this);
4213    
4214                    if (list == null) {
4215                            StringBundler query = null;
4216                            String sql = null;
4217    
4218                            if (orderByComparator != null) {
4219                                    query = new StringBundler(2 +
4220                                                    (orderByComparator.getOrderByFields().length * 3));
4221    
4222                                    query.append(_SQL_SELECT_LAYOUT);
4223    
4224                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4225                                            orderByComparator);
4226    
4227                                    sql = query.toString();
4228                            }
4229                            else {
4230                                    sql = _SQL_SELECT_LAYOUT.concat(LayoutModelImpl.ORDER_BY_JPQL);
4231                            }
4232    
4233                            Session session = null;
4234    
4235                            try {
4236                                    session = openSession();
4237    
4238                                    Query q = session.createQuery(sql);
4239    
4240                                    if (orderByComparator == null) {
4241                                            list = (List<Layout>)QueryUtil.list(q, getDialect(), start,
4242                                                            end, false);
4243    
4244                                            Collections.sort(list);
4245                                    }
4246                                    else {
4247                                            list = (List<Layout>)QueryUtil.list(q, getDialect(), start,
4248                                                            end);
4249                                    }
4250                            }
4251                            catch (Exception e) {
4252                                    throw processException(e);
4253                            }
4254                            finally {
4255                                    if (list == null) {
4256                                            FinderCacheUtil.removeResult(FINDER_PATH_FIND_ALL,
4257                                                    finderArgs);
4258                                    }
4259                                    else {
4260                                            cacheResult(list);
4261    
4262                                            FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs,
4263                                                    list);
4264                                    }
4265    
4266                                    closeSession(session);
4267                            }
4268                    }
4269    
4270                    return list;
4271            }
4272    
4273            /**
4274             * Removes all the layouts where uuid = &#63; from the database.
4275             *
4276             * @param uuid the uuid to search with
4277             * @throws SystemException if a system exception occurred
4278             */
4279            public void removeByUuid(String uuid) throws SystemException {
4280                    for (Layout layout : findByUuid(uuid)) {
4281                            remove(layout);
4282                    }
4283            }
4284    
4285            /**
4286             * Removes the layout where uuid = &#63; and groupId = &#63; from the database.
4287             *
4288             * @param uuid the uuid to search with
4289             * @param groupId the group id to search with
4290             * @throws SystemException if a system exception occurred
4291             */
4292            public void removeByUUID_G(String uuid, long groupId)
4293                    throws NoSuchLayoutException, SystemException {
4294                    Layout layout = findByUUID_G(uuid, groupId);
4295    
4296                    remove(layout);
4297            }
4298    
4299            /**
4300             * Removes all the layouts where groupId = &#63; from the database.
4301             *
4302             * @param groupId the group id to search with
4303             * @throws SystemException if a system exception occurred
4304             */
4305            public void removeByGroupId(long groupId) throws SystemException {
4306                    for (Layout layout : findByGroupId(groupId)) {
4307                            remove(layout);
4308                    }
4309            }
4310    
4311            /**
4312             * Removes all the layouts where companyId = &#63; from the database.
4313             *
4314             * @param companyId the company id to search with
4315             * @throws SystemException if a system exception occurred
4316             */
4317            public void removeByCompanyId(long companyId) throws SystemException {
4318                    for (Layout layout : findByCompanyId(companyId)) {
4319                            remove(layout);
4320                    }
4321            }
4322    
4323            /**
4324             * Removes the layout where dlFolderId = &#63; from the database.
4325             *
4326             * @param dlFolderId the dl folder id to search with
4327             * @throws SystemException if a system exception occurred
4328             */
4329            public void removeByDLFolderId(long dlFolderId)
4330                    throws NoSuchLayoutException, SystemException {
4331                    Layout layout = findByDLFolderId(dlFolderId);
4332    
4333                    remove(layout);
4334            }
4335    
4336            /**
4337             * Removes the layout where iconImageId = &#63; from the database.
4338             *
4339             * @param iconImageId the icon image id to search with
4340             * @throws SystemException if a system exception occurred
4341             */
4342            public void removeByIconImageId(long iconImageId)
4343                    throws NoSuchLayoutException, SystemException {
4344                    Layout layout = findByIconImageId(iconImageId);
4345    
4346                    remove(layout);
4347            }
4348    
4349            /**
4350             * Removes all the layouts where groupId = &#63; and privateLayout = &#63; from the database.
4351             *
4352             * @param groupId the group id to search with
4353             * @param privateLayout the private layout to search with
4354             * @throws SystemException if a system exception occurred
4355             */
4356            public void removeByG_P(long groupId, boolean privateLayout)
4357                    throws SystemException {
4358                    for (Layout layout : findByG_P(groupId, privateLayout)) {
4359                            remove(layout);
4360                    }
4361            }
4362    
4363            /**
4364             * Removes the layout where groupId = &#63; and privateLayout = &#63; and layoutId = &#63; from the database.
4365             *
4366             * @param groupId the group id to search with
4367             * @param privateLayout the private layout to search with
4368             * @param layoutId the layout id to search with
4369             * @throws SystemException if a system exception occurred
4370             */
4371            public void removeByG_P_L(long groupId, boolean privateLayout, long layoutId)
4372                    throws NoSuchLayoutException, SystemException {
4373                    Layout layout = findByG_P_L(groupId, privateLayout, layoutId);
4374    
4375                    remove(layout);
4376            }
4377    
4378            /**
4379             * Removes all the layouts where groupId = &#63; and privateLayout = &#63; and parentLayoutId = &#63; from the database.
4380             *
4381             * @param groupId the group id to search with
4382             * @param privateLayout the private layout to search with
4383             * @param parentLayoutId the parent layout id to search with
4384             * @throws SystemException if a system exception occurred
4385             */
4386            public void removeByG_P_P(long groupId, boolean privateLayout,
4387                    long parentLayoutId) throws SystemException {
4388                    for (Layout layout : findByG_P_P(groupId, privateLayout, parentLayoutId)) {
4389                            remove(layout);
4390                    }
4391            }
4392    
4393            /**
4394             * Removes the layout where groupId = &#63; and privateLayout = &#63; and friendlyURL = &#63; from the database.
4395             *
4396             * @param groupId the group id to search with
4397             * @param privateLayout the private layout to search with
4398             * @param friendlyURL the friendly u r l to search with
4399             * @throws SystemException if a system exception occurred
4400             */
4401            public void removeByG_P_F(long groupId, boolean privateLayout,
4402                    String friendlyURL) throws NoSuchLayoutException, SystemException {
4403                    Layout layout = findByG_P_F(groupId, privateLayout, friendlyURL);
4404    
4405                    remove(layout);
4406            }
4407    
4408            /**
4409             * Removes all the layouts where groupId = &#63; and privateLayout = &#63; and type = &#63; from the database.
4410             *
4411             * @param groupId the group id to search with
4412             * @param privateLayout the private layout to search with
4413             * @param type the type to search with
4414             * @throws SystemException if a system exception occurred
4415             */
4416            public void removeByG_P_T(long groupId, boolean privateLayout, String type)
4417                    throws SystemException {
4418                    for (Layout layout : findByG_P_T(groupId, privateLayout, type)) {
4419                            remove(layout);
4420                    }
4421            }
4422    
4423            /**
4424             * Removes all the layouts from the database.
4425             *
4426             * @throws SystemException if a system exception occurred
4427             */
4428            public void removeAll() throws SystemException {
4429                    for (Layout layout : findAll()) {
4430                            remove(layout);
4431                    }
4432            }
4433    
4434            /**
4435             * Counts all the layouts where uuid = &#63;.
4436             *
4437             * @param uuid the uuid to search with
4438             * @return the number of matching layouts
4439             * @throws SystemException if a system exception occurred
4440             */
4441            public int countByUuid(String uuid) throws SystemException {
4442                    Object[] finderArgs = new Object[] { uuid };
4443    
4444                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
4445                                    finderArgs, this);
4446    
4447                    if (count == null) {
4448                            StringBundler query = new StringBundler(2);
4449    
4450                            query.append(_SQL_COUNT_LAYOUT_WHERE);
4451    
4452                            if (uuid == null) {
4453                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
4454                            }
4455                            else {
4456                                    if (uuid.equals(StringPool.BLANK)) {
4457                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
4458                                    }
4459                                    else {
4460                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
4461                                    }
4462                            }
4463    
4464                            String sql = query.toString();
4465    
4466                            Session session = null;
4467    
4468                            try {
4469                                    session = openSession();
4470    
4471                                    Query q = session.createQuery(sql);
4472    
4473                                    QueryPos qPos = QueryPos.getInstance(q);
4474    
4475                                    if (uuid != null) {
4476                                            qPos.add(uuid);
4477                                    }
4478    
4479                                    count = (Long)q.uniqueResult();
4480                            }
4481                            catch (Exception e) {
4482                                    throw processException(e);
4483                            }
4484                            finally {
4485                                    if (count == null) {
4486                                            count = Long.valueOf(0);
4487                                    }
4488    
4489                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
4490                                            finderArgs, count);
4491    
4492                                    closeSession(session);
4493                            }
4494                    }
4495    
4496                    return count.intValue();
4497            }
4498    
4499            /**
4500             * Counts all the layouts where uuid = &#63; and groupId = &#63;.
4501             *
4502             * @param uuid the uuid to search with
4503             * @param groupId the group id to search with
4504             * @return the number of matching layouts
4505             * @throws SystemException if a system exception occurred
4506             */
4507            public int countByUUID_G(String uuid, long groupId)
4508                    throws SystemException {
4509                    Object[] finderArgs = new Object[] { uuid, groupId };
4510    
4511                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
4512                                    finderArgs, this);
4513    
4514                    if (count == null) {
4515                            StringBundler query = new StringBundler(3);
4516    
4517                            query.append(_SQL_COUNT_LAYOUT_WHERE);
4518    
4519                            if (uuid == null) {
4520                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
4521                            }
4522                            else {
4523                                    if (uuid.equals(StringPool.BLANK)) {
4524                                            query.append(_FINDER_COLUMN_UUID_G_UUID_3);
4525                                    }
4526                                    else {
4527                                            query.append(_FINDER_COLUMN_UUID_G_UUID_2);
4528                                    }
4529                            }
4530    
4531                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
4532    
4533                            String sql = query.toString();
4534    
4535                            Session session = null;
4536    
4537                            try {
4538                                    session = openSession();
4539    
4540                                    Query q = session.createQuery(sql);
4541    
4542                                    QueryPos qPos = QueryPos.getInstance(q);
4543    
4544                                    if (uuid != null) {
4545                                            qPos.add(uuid);
4546                                    }
4547    
4548                                    qPos.add(groupId);
4549    
4550                                    count = (Long)q.uniqueResult();
4551                            }
4552                            catch (Exception e) {
4553                                    throw processException(e);
4554                            }
4555                            finally {
4556                                    if (count == null) {
4557                                            count = Long.valueOf(0);
4558                                    }
4559    
4560                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
4561                                            finderArgs, count);
4562    
4563                                    closeSession(session);
4564                            }
4565                    }
4566    
4567                    return count.intValue();
4568            }
4569    
4570            /**
4571             * Counts all the layouts where groupId = &#63;.
4572             *
4573             * @param groupId the group id to search with
4574             * @return the number of matching layouts
4575             * @throws SystemException if a system exception occurred
4576             */
4577            public int countByGroupId(long groupId) throws SystemException {
4578                    Object[] finderArgs = new Object[] { groupId };
4579    
4580                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
4581                                    finderArgs, this);
4582    
4583                    if (count == null) {
4584                            StringBundler query = new StringBundler(2);
4585    
4586                            query.append(_SQL_COUNT_LAYOUT_WHERE);
4587    
4588                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
4589    
4590                            String sql = query.toString();
4591    
4592                            Session session = null;
4593    
4594                            try {
4595                                    session = openSession();
4596    
4597                                    Query q = session.createQuery(sql);
4598    
4599                                    QueryPos qPos = QueryPos.getInstance(q);
4600    
4601                                    qPos.add(groupId);
4602    
4603                                    count = (Long)q.uniqueResult();
4604                            }
4605                            catch (Exception e) {
4606                                    throw processException(e);
4607                            }
4608                            finally {
4609                                    if (count == null) {
4610                                            count = Long.valueOf(0);
4611                                    }
4612    
4613                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
4614                                            finderArgs, count);
4615    
4616                                    closeSession(session);
4617                            }
4618                    }
4619    
4620                    return count.intValue();
4621            }
4622    
4623            /**
4624             * Filters by the user's permissions and counts all the layouts where groupId = &#63;.
4625             *
4626             * @param groupId the group id to search with
4627             * @return the number of matching layouts that the user has permission to view
4628             * @throws SystemException if a system exception occurred
4629             */
4630            public int filterCountByGroupId(long groupId) throws SystemException {
4631                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4632                            return countByGroupId(groupId);
4633                    }
4634    
4635                    StringBundler query = new StringBundler(2);
4636    
4637                    query.append(_FILTER_SQL_COUNT_LAYOUT_WHERE);
4638    
4639                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
4640    
4641                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4642                                    Layout.class.getName(), _FILTER_COLUMN_PK,
4643                                    _FILTER_COLUMN_USERID, groupId);
4644    
4645                    Session session = null;
4646    
4647                    try {
4648                            session = openSession();
4649    
4650                            SQLQuery q = session.createSQLQuery(sql);
4651    
4652                            q.addScalar(COUNT_COLUMN_NAME,
4653                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
4654    
4655                            QueryPos qPos = QueryPos.getInstance(q);
4656    
4657                            qPos.add(groupId);
4658    
4659                            Long count = (Long)q.uniqueResult();
4660    
4661                            return count.intValue();
4662                    }
4663                    catch (Exception e) {
4664                            throw processException(e);
4665                    }
4666                    finally {
4667                            closeSession(session);
4668                    }
4669            }
4670    
4671            /**
4672             * Counts all the layouts where companyId = &#63;.
4673             *
4674             * @param companyId the company id to search with
4675             * @return the number of matching layouts
4676             * @throws SystemException if a system exception occurred
4677             */
4678            public int countByCompanyId(long companyId) throws SystemException {
4679                    Object[] finderArgs = new Object[] { companyId };
4680    
4681                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
4682                                    finderArgs, this);
4683    
4684                    if (count == null) {
4685                            StringBundler query = new StringBundler(2);
4686    
4687                            query.append(_SQL_COUNT_LAYOUT_WHERE);
4688    
4689                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
4690    
4691                            String sql = query.toString();
4692    
4693                            Session session = null;
4694    
4695                            try {
4696                                    session = openSession();
4697    
4698                                    Query q = session.createQuery(sql);
4699    
4700                                    QueryPos qPos = QueryPos.getInstance(q);
4701    
4702                                    qPos.add(companyId);
4703    
4704                                    count = (Long)q.uniqueResult();
4705                            }
4706                            catch (Exception e) {
4707                                    throw processException(e);
4708                            }
4709                            finally {
4710                                    if (count == null) {
4711                                            count = Long.valueOf(0);
4712                                    }
4713    
4714                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
4715                                            finderArgs, count);
4716    
4717                                    closeSession(session);
4718                            }
4719                    }
4720    
4721                    return count.intValue();
4722            }
4723    
4724            /**
4725             * Counts all the layouts where dlFolderId = &#63;.
4726             *
4727             * @param dlFolderId the dl folder id to search with
4728             * @return the number of matching layouts
4729             * @throws SystemException if a system exception occurred
4730             */
4731            public int countByDLFolderId(long dlFolderId) throws SystemException {
4732                    Object[] finderArgs = new Object[] { dlFolderId };
4733    
4734                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_DLFOLDERID,
4735                                    finderArgs, this);
4736    
4737                    if (count == null) {
4738                            StringBundler query = new StringBundler(2);
4739    
4740                            query.append(_SQL_COUNT_LAYOUT_WHERE);
4741    
4742                            query.append(_FINDER_COLUMN_DLFOLDERID_DLFOLDERID_2);
4743    
4744                            String sql = query.toString();
4745    
4746                            Session session = null;
4747    
4748                            try {
4749                                    session = openSession();
4750    
4751                                    Query q = session.createQuery(sql);
4752    
4753                                    QueryPos qPos = QueryPos.getInstance(q);
4754    
4755                                    qPos.add(dlFolderId);
4756    
4757                                    count = (Long)q.uniqueResult();
4758                            }
4759                            catch (Exception e) {
4760                                    throw processException(e);
4761                            }
4762                            finally {
4763                                    if (count == null) {
4764                                            count = Long.valueOf(0);
4765                                    }
4766    
4767                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_DLFOLDERID,
4768                                            finderArgs, count);
4769    
4770                                    closeSession(session);
4771                            }
4772                    }
4773    
4774                    return count.intValue();
4775            }
4776    
4777            /**
4778             * Counts all the layouts where iconImageId = &#63;.
4779             *
4780             * @param iconImageId the icon image id to search with
4781             * @return the number of matching layouts
4782             * @throws SystemException if a system exception occurred
4783             */
4784            public int countByIconImageId(long iconImageId) throws SystemException {
4785                    Object[] finderArgs = new Object[] { iconImageId };
4786    
4787                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_ICONIMAGEID,
4788                                    finderArgs, this);
4789    
4790                    if (count == null) {
4791                            StringBundler query = new StringBundler(2);
4792    
4793                            query.append(_SQL_COUNT_LAYOUT_WHERE);
4794    
4795                            query.append(_FINDER_COLUMN_ICONIMAGEID_ICONIMAGEID_2);
4796    
4797                            String sql = query.toString();
4798    
4799                            Session session = null;
4800    
4801                            try {
4802                                    session = openSession();
4803    
4804                                    Query q = session.createQuery(sql);
4805    
4806                                    QueryPos qPos = QueryPos.getInstance(q);
4807    
4808                                    qPos.add(iconImageId);
4809    
4810                                    count = (Long)q.uniqueResult();
4811                            }
4812                            catch (Exception e) {
4813                                    throw processException(e);
4814                            }
4815                            finally {
4816                                    if (count == null) {
4817                                            count = Long.valueOf(0);
4818                                    }
4819    
4820                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ICONIMAGEID,
4821                                            finderArgs, count);
4822    
4823                                    closeSession(session);
4824                            }
4825                    }
4826    
4827                    return count.intValue();
4828            }
4829    
4830            /**
4831             * Counts all the layouts where groupId = &#63; and privateLayout = &#63;.
4832             *
4833             * @param groupId the group id to search with
4834             * @param privateLayout the private layout to search with
4835             * @return the number of matching layouts
4836             * @throws SystemException if a system exception occurred
4837             */
4838            public int countByG_P(long groupId, boolean privateLayout)
4839                    throws SystemException {
4840                    Object[] finderArgs = new Object[] { groupId, privateLayout };
4841    
4842                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_P,
4843                                    finderArgs, this);
4844    
4845                    if (count == null) {
4846                            StringBundler query = new StringBundler(3);
4847    
4848                            query.append(_SQL_COUNT_LAYOUT_WHERE);
4849    
4850                            query.append(_FINDER_COLUMN_G_P_GROUPID_2);
4851    
4852                            query.append(_FINDER_COLUMN_G_P_PRIVATELAYOUT_2);
4853    
4854                            String sql = query.toString();
4855    
4856                            Session session = null;
4857    
4858                            try {
4859                                    session = openSession();
4860    
4861                                    Query q = session.createQuery(sql);
4862    
4863                                    QueryPos qPos = QueryPos.getInstance(q);
4864    
4865                                    qPos.add(groupId);
4866    
4867                                    qPos.add(privateLayout);
4868    
4869                                    count = (Long)q.uniqueResult();
4870                            }
4871                            catch (Exception e) {
4872                                    throw processException(e);
4873                            }
4874                            finally {
4875                                    if (count == null) {
4876                                            count = Long.valueOf(0);
4877                                    }
4878    
4879                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_P, finderArgs,
4880                                            count);
4881    
4882                                    closeSession(session);
4883                            }
4884                    }
4885    
4886                    return count.intValue();
4887            }
4888    
4889            /**
4890             * Filters by the user's permissions and counts all the layouts where groupId = &#63; and privateLayout = &#63;.
4891             *
4892             * @param groupId the group id to search with
4893             * @param privateLayout the private layout to search with
4894             * @return the number of matching layouts that the user has permission to view
4895             * @throws SystemException if a system exception occurred
4896             */
4897            public int filterCountByG_P(long groupId, boolean privateLayout)
4898                    throws SystemException {
4899                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4900                            return countByG_P(groupId, privateLayout);
4901                    }
4902    
4903                    StringBundler query = new StringBundler(3);
4904    
4905                    query.append(_FILTER_SQL_COUNT_LAYOUT_WHERE);
4906    
4907                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
4908    
4909                    query.append(_FINDER_COLUMN_G_P_PRIVATELAYOUT_2);
4910    
4911                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4912                                    Layout.class.getName(), _FILTER_COLUMN_PK,
4913                                    _FILTER_COLUMN_USERID, groupId);
4914    
4915                    Session session = null;
4916    
4917                    try {
4918                            session = openSession();
4919    
4920                            SQLQuery q = session.createSQLQuery(sql);
4921    
4922                            q.addScalar(COUNT_COLUMN_NAME,
4923                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
4924    
4925                            QueryPos qPos = QueryPos.getInstance(q);
4926    
4927                            qPos.add(groupId);
4928    
4929                            qPos.add(privateLayout);
4930    
4931                            Long count = (Long)q.uniqueResult();
4932    
4933                            return count.intValue();
4934                    }
4935                    catch (Exception e) {
4936                            throw processException(e);
4937                    }
4938                    finally {
4939                            closeSession(session);
4940                    }
4941            }
4942    
4943            /**
4944             * Counts all the layouts where groupId = &#63; and privateLayout = &#63; and layoutId = &#63;.
4945             *
4946             * @param groupId the group id to search with
4947             * @param privateLayout the private layout to search with
4948             * @param layoutId the layout id to search with
4949             * @return the number of matching layouts
4950             * @throws SystemException if a system exception occurred
4951             */
4952            public int countByG_P_L(long groupId, boolean privateLayout, long layoutId)
4953                    throws SystemException {
4954                    Object[] finderArgs = new Object[] { groupId, privateLayout, layoutId };
4955    
4956                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_P_L,
4957                                    finderArgs, this);
4958    
4959                    if (count == null) {
4960                            StringBundler query = new StringBundler(4);
4961    
4962                            query.append(_SQL_COUNT_LAYOUT_WHERE);
4963    
4964                            query.append(_FINDER_COLUMN_G_P_L_GROUPID_2);
4965    
4966                            query.append(_FINDER_COLUMN_G_P_L_PRIVATELAYOUT_2);
4967    
4968                            query.append(_FINDER_COLUMN_G_P_L_LAYOUTID_2);
4969    
4970                            String sql = query.toString();
4971    
4972                            Session session = null;
4973    
4974                            try {
4975                                    session = openSession();
4976    
4977                                    Query q = session.createQuery(sql);
4978    
4979                                    QueryPos qPos = QueryPos.getInstance(q);
4980    
4981                                    qPos.add(groupId);
4982    
4983                                    qPos.add(privateLayout);
4984    
4985                                    qPos.add(layoutId);
4986    
4987                                    count = (Long)q.uniqueResult();
4988                            }
4989                            catch (Exception e) {
4990                                    throw processException(e);
4991                            }
4992                            finally {
4993                                    if (count == null) {
4994                                            count = Long.valueOf(0);
4995                                    }
4996    
4997                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_P_L,
4998                                            finderArgs, count);
4999    
5000                                    closeSession(session);
5001                            }
5002                    }
5003    
5004                    return count.intValue();
5005            }
5006    
5007            /**
5008             * Counts all the layouts where groupId = &#63; and privateLayout = &#63; and parentLayoutId = &#63;.
5009             *
5010             * @param groupId the group id to search with
5011             * @param privateLayout the private layout to search with
5012             * @param parentLayoutId the parent layout id to search with
5013             * @return the number of matching layouts
5014             * @throws SystemException if a system exception occurred
5015             */
5016            public int countByG_P_P(long groupId, boolean privateLayout,
5017                    long parentLayoutId) throws SystemException {
5018                    Object[] finderArgs = new Object[] {
5019                                    groupId, privateLayout, parentLayoutId
5020                            };
5021    
5022                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_P_P,
5023                                    finderArgs, this);
5024    
5025                    if (count == null) {
5026                            StringBundler query = new StringBundler(4);
5027    
5028                            query.append(_SQL_COUNT_LAYOUT_WHERE);
5029    
5030                            query.append(_FINDER_COLUMN_G_P_P_GROUPID_2);
5031    
5032                            query.append(_FINDER_COLUMN_G_P_P_PRIVATELAYOUT_2);
5033    
5034                            query.append(_FINDER_COLUMN_G_P_P_PARENTLAYOUTID_2);
5035    
5036                            String sql = query.toString();
5037    
5038                            Session session = null;
5039    
5040                            try {
5041                                    session = openSession();
5042    
5043                                    Query q = session.createQuery(sql);
5044    
5045                                    QueryPos qPos = QueryPos.getInstance(q);
5046    
5047                                    qPos.add(groupId);
5048    
5049                                    qPos.add(privateLayout);
5050    
5051                                    qPos.add(parentLayoutId);
5052    
5053                                    count = (Long)q.uniqueResult();
5054                            }
5055                            catch (Exception e) {
5056                                    throw processException(e);
5057                            }
5058                            finally {
5059                                    if (count == null) {
5060                                            count = Long.valueOf(0);
5061                                    }
5062    
5063                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_P_P,
5064                                            finderArgs, count);
5065    
5066                                    closeSession(session);
5067                            }
5068                    }
5069    
5070                    return count.intValue();
5071            }
5072    
5073            /**
5074             * Filters by the user's permissions and counts all the layouts where groupId = &#63; and privateLayout = &#63; and parentLayoutId = &#63;.
5075             *
5076             * @param groupId the group id to search with
5077             * @param privateLayout the private layout to search with
5078             * @param parentLayoutId the parent layout id to search with
5079             * @return the number of matching layouts that the user has permission to view
5080             * @throws SystemException if a system exception occurred
5081             */
5082            public int filterCountByG_P_P(long groupId, boolean privateLayout,
5083                    long parentLayoutId) throws SystemException {
5084                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5085                            return countByG_P_P(groupId, privateLayout, parentLayoutId);
5086                    }
5087    
5088                    StringBundler query = new StringBundler(4);
5089    
5090                    query.append(_FILTER_SQL_COUNT_LAYOUT_WHERE);
5091    
5092                    query.append(_FINDER_COLUMN_G_P_P_GROUPID_2);
5093    
5094                    query.append(_FINDER_COLUMN_G_P_P_PRIVATELAYOUT_2);
5095    
5096                    query.append(_FINDER_COLUMN_G_P_P_PARENTLAYOUTID_2);
5097    
5098                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5099                                    Layout.class.getName(), _FILTER_COLUMN_PK,
5100                                    _FILTER_COLUMN_USERID, groupId);
5101    
5102                    Session session = null;
5103    
5104                    try {
5105                            session = openSession();
5106    
5107                            SQLQuery q = session.createSQLQuery(sql);
5108    
5109                            q.addScalar(COUNT_COLUMN_NAME,
5110                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
5111    
5112                            QueryPos qPos = QueryPos.getInstance(q);
5113    
5114                            qPos.add(groupId);
5115    
5116                            qPos.add(privateLayout);
5117    
5118                            qPos.add(parentLayoutId);
5119    
5120                            Long count = (Long)q.uniqueResult();
5121    
5122                            return count.intValue();
5123                    }
5124                    catch (Exception e) {
5125                            throw processException(e);
5126                    }
5127                    finally {
5128                            closeSession(session);
5129                    }
5130            }
5131    
5132            /**
5133             * Counts all the layouts where groupId = &#63; and privateLayout = &#63; and friendlyURL = &#63;.
5134             *
5135             * @param groupId the group id to search with
5136             * @param privateLayout the private layout to search with
5137             * @param friendlyURL the friendly u r l to search with
5138             * @return the number of matching layouts
5139             * @throws SystemException if a system exception occurred
5140             */
5141            public int countByG_P_F(long groupId, boolean privateLayout,
5142                    String friendlyURL) throws SystemException {
5143                    Object[] finderArgs = new Object[] { groupId, privateLayout, friendlyURL };
5144    
5145                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_P_F,
5146                                    finderArgs, this);
5147    
5148                    if (count == null) {
5149                            StringBundler query = new StringBundler(4);
5150    
5151                            query.append(_SQL_COUNT_LAYOUT_WHERE);
5152    
5153                            query.append(_FINDER_COLUMN_G_P_F_GROUPID_2);
5154    
5155                            query.append(_FINDER_COLUMN_G_P_F_PRIVATELAYOUT_2);
5156    
5157                            if (friendlyURL == null) {
5158                                    query.append(_FINDER_COLUMN_G_P_F_FRIENDLYURL_1);
5159                            }
5160                            else {
5161                                    if (friendlyURL.equals(StringPool.BLANK)) {
5162                                            query.append(_FINDER_COLUMN_G_P_F_FRIENDLYURL_3);
5163                                    }
5164                                    else {
5165                                            query.append(_FINDER_COLUMN_G_P_F_FRIENDLYURL_2);
5166                                    }
5167                            }
5168    
5169                            String sql = query.toString();
5170    
5171                            Session session = null;
5172    
5173                            try {
5174                                    session = openSession();
5175    
5176                                    Query q = session.createQuery(sql);
5177    
5178                                    QueryPos qPos = QueryPos.getInstance(q);
5179    
5180                                    qPos.add(groupId);
5181    
5182                                    qPos.add(privateLayout);
5183    
5184                                    if (friendlyURL != null) {
5185                                            qPos.add(friendlyURL);
5186                                    }
5187    
5188                                    count = (Long)q.uniqueResult();
5189                            }
5190                            catch (Exception e) {
5191                                    throw processException(e);
5192                            }
5193                            finally {
5194                                    if (count == null) {
5195                                            count = Long.valueOf(0);
5196                                    }
5197    
5198                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_P_F,
5199                                            finderArgs, count);
5200    
5201                                    closeSession(session);
5202                            }
5203                    }
5204    
5205                    return count.intValue();
5206            }
5207    
5208            /**
5209             * Counts all the layouts where groupId = &#63; and privateLayout = &#63; and type = &#63;.
5210             *
5211             * @param groupId the group id to search with
5212             * @param privateLayout the private layout to search with
5213             * @param type the type to search with
5214             * @return the number of matching layouts
5215             * @throws SystemException if a system exception occurred
5216             */
5217            public int countByG_P_T(long groupId, boolean privateLayout, String type)
5218                    throws SystemException {
5219                    Object[] finderArgs = new Object[] { groupId, privateLayout, type };
5220    
5221                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_P_T,
5222                                    finderArgs, this);
5223    
5224                    if (count == null) {
5225                            StringBundler query = new StringBundler(4);
5226    
5227                            query.append(_SQL_COUNT_LAYOUT_WHERE);
5228    
5229                            query.append(_FINDER_COLUMN_G_P_T_GROUPID_2);
5230    
5231                            query.append(_FINDER_COLUMN_G_P_T_PRIVATELAYOUT_2);
5232    
5233                            if (type == null) {
5234                                    query.append(_FINDER_COLUMN_G_P_T_TYPE_1);
5235                            }
5236                            else {
5237                                    if (type.equals(StringPool.BLANK)) {
5238                                            query.append(_FINDER_COLUMN_G_P_T_TYPE_3);
5239                                    }
5240                                    else {
5241                                            query.append(_FINDER_COLUMN_G_P_T_TYPE_2);
5242                                    }
5243                            }
5244    
5245                            String sql = query.toString();
5246    
5247                            Session session = null;
5248    
5249                            try {
5250                                    session = openSession();
5251    
5252                                    Query q = session.createQuery(sql);
5253    
5254                                    QueryPos qPos = QueryPos.getInstance(q);
5255    
5256                                    qPos.add(groupId);
5257    
5258                                    qPos.add(privateLayout);
5259    
5260                                    if (type != null) {
5261                                            qPos.add(type);
5262                                    }
5263    
5264                                    count = (Long)q.uniqueResult();
5265                            }
5266                            catch (Exception e) {
5267                                    throw processException(e);
5268                            }
5269                            finally {
5270                                    if (count == null) {
5271                                            count = Long.valueOf(0);
5272                                    }
5273    
5274                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_P_T,
5275                                            finderArgs, count);
5276    
5277                                    closeSession(session);
5278                            }
5279                    }
5280    
5281                    return count.intValue();
5282            }
5283    
5284            /**
5285             * Filters by the user's permissions and counts all the layouts where groupId = &#63; and privateLayout = &#63; and type = &#63;.
5286             *
5287             * @param groupId the group id to search with
5288             * @param privateLayout the private layout to search with
5289             * @param type the type to search with
5290             * @return the number of matching layouts that the user has permission to view
5291             * @throws SystemException if a system exception occurred
5292             */
5293            public int filterCountByG_P_T(long groupId, boolean privateLayout,
5294                    String type) throws SystemException {
5295                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5296                            return countByG_P_T(groupId, privateLayout, type);
5297                    }
5298    
5299                    StringBundler query = new StringBundler(4);
5300    
5301                    query.append(_FILTER_SQL_COUNT_LAYOUT_WHERE);
5302    
5303                    query.append(_FINDER_COLUMN_G_P_T_GROUPID_2);
5304    
5305                    query.append(_FINDER_COLUMN_G_P_T_PRIVATELAYOUT_2);
5306    
5307                    if (type == null) {
5308                            query.append(_FINDER_COLUMN_G_P_T_TYPE_1);
5309                    }
5310                    else {
5311                            if (type.equals(StringPool.BLANK)) {
5312                                    query.append(_FINDER_COLUMN_G_P_T_TYPE_3);
5313                            }
5314                            else {
5315                                    query.append(_FINDER_COLUMN_G_P_T_TYPE_2);
5316                            }
5317                    }
5318    
5319                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5320                                    Layout.class.getName(), _FILTER_COLUMN_PK,
5321                                    _FILTER_COLUMN_USERID, groupId);
5322    
5323                    Session session = null;
5324    
5325                    try {
5326                            session = openSession();
5327    
5328                            SQLQuery q = session.createSQLQuery(sql);
5329    
5330                            q.addScalar(COUNT_COLUMN_NAME,
5331                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
5332    
5333                            QueryPos qPos = QueryPos.getInstance(q);
5334    
5335                            qPos.add(groupId);
5336    
5337                            qPos.add(privateLayout);
5338    
5339                            if (type != null) {
5340                                    qPos.add(type);
5341                            }
5342    
5343                            Long count = (Long)q.uniqueResult();
5344    
5345                            return count.intValue();
5346                    }
5347                    catch (Exception e) {
5348                            throw processException(e);
5349                    }
5350                    finally {
5351                            closeSession(session);
5352                    }
5353            }
5354    
5355            /**
5356             * Counts all the layouts.
5357             *
5358             * @return the number of layouts
5359             * @throws SystemException if a system exception occurred
5360             */
5361            public int countAll() throws SystemException {
5362                    Object[] finderArgs = new Object[0];
5363    
5364                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
5365                                    finderArgs, this);
5366    
5367                    if (count == null) {
5368                            Session session = null;
5369    
5370                            try {
5371                                    session = openSession();
5372    
5373                                    Query q = session.createQuery(_SQL_COUNT_LAYOUT);
5374    
5375                                    count = (Long)q.uniqueResult();
5376                            }
5377                            catch (Exception e) {
5378                                    throw processException(e);
5379                            }
5380                            finally {
5381                                    if (count == null) {
5382                                            count = Long.valueOf(0);
5383                                    }
5384    
5385                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
5386                                            count);
5387    
5388                                    closeSession(session);
5389                            }
5390                    }
5391    
5392                    return count.intValue();
5393            }
5394    
5395            /**
5396             * Initializes the layout persistence.
5397             */
5398            public void afterPropertiesSet() {
5399                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
5400                                            com.liferay.portal.util.PropsUtil.get(
5401                                                    "value.object.listener.com.liferay.portal.model.Layout")));
5402    
5403                    if (listenerClassNames.length > 0) {
5404                            try {
5405                                    List<ModelListener<Layout>> listenersList = new ArrayList<ModelListener<Layout>>();
5406    
5407                                    for (String listenerClassName : listenerClassNames) {
5408                                            listenersList.add((ModelListener<Layout>)InstanceFactory.newInstance(
5409                                                            listenerClassName));
5410                                    }
5411    
5412                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
5413                            }
5414                            catch (Exception e) {
5415                                    _log.error(e);
5416                            }
5417                    }
5418            }
5419    
5420            public void destroy() {
5421                    EntityCacheUtil.removeCache(LayoutImpl.class.getName());
5422                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
5423                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
5424            }
5425    
5426            @BeanReference(type = AccountPersistence.class)
5427            protected AccountPersistence accountPersistence;
5428            @BeanReference(type = AddressPersistence.class)
5429            protected AddressPersistence addressPersistence;
5430            @BeanReference(type = BrowserTrackerPersistence.class)
5431            protected BrowserTrackerPersistence browserTrackerPersistence;
5432            @BeanReference(type = ClassNamePersistence.class)
5433            protected ClassNamePersistence classNamePersistence;
5434            @BeanReference(type = ClusterGroupPersistence.class)
5435            protected ClusterGroupPersistence clusterGroupPersistence;
5436            @BeanReference(type = CompanyPersistence.class)
5437            protected CompanyPersistence companyPersistence;
5438            @BeanReference(type = ContactPersistence.class)
5439            protected ContactPersistence contactPersistence;
5440            @BeanReference(type = CountryPersistence.class)
5441            protected CountryPersistence countryPersistence;
5442            @BeanReference(type = EmailAddressPersistence.class)
5443            protected EmailAddressPersistence emailAddressPersistence;
5444            @BeanReference(type = GroupPersistence.class)
5445            protected GroupPersistence groupPersistence;
5446            @BeanReference(type = ImagePersistence.class)
5447            protected ImagePersistence imagePersistence;
5448            @BeanReference(type = LayoutPersistence.class)
5449            protected LayoutPersistence layoutPersistence;
5450            @BeanReference(type = LayoutPrototypePersistence.class)
5451            protected LayoutPrototypePersistence layoutPrototypePersistence;
5452            @BeanReference(type = LayoutSetPersistence.class)
5453            protected LayoutSetPersistence layoutSetPersistence;
5454            @BeanReference(type = LayoutSetPrototypePersistence.class)
5455            protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
5456            @BeanReference(type = ListTypePersistence.class)
5457            protected ListTypePersistence listTypePersistence;
5458            @BeanReference(type = LockPersistence.class)
5459            protected LockPersistence lockPersistence;
5460            @BeanReference(type = MembershipRequestPersistence.class)
5461            protected MembershipRequestPersistence membershipRequestPersistence;
5462            @BeanReference(type = OrganizationPersistence.class)
5463            protected OrganizationPersistence organizationPersistence;
5464            @BeanReference(type = OrgGroupPermissionPersistence.class)
5465            protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
5466            @BeanReference(type = OrgGroupRolePersistence.class)
5467            protected OrgGroupRolePersistence orgGroupRolePersistence;
5468            @BeanReference(type = OrgLaborPersistence.class)
5469            protected OrgLaborPersistence orgLaborPersistence;
5470            @BeanReference(type = PasswordPolicyPersistence.class)
5471            protected PasswordPolicyPersistence passwordPolicyPersistence;
5472            @BeanReference(type = PasswordPolicyRelPersistence.class)
5473            protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
5474            @BeanReference(type = PasswordTrackerPersistence.class)
5475            protected PasswordTrackerPersistence passwordTrackerPersistence;
5476            @BeanReference(type = PermissionPersistence.class)
5477            protected PermissionPersistence permissionPersistence;
5478            @BeanReference(type = PhonePersistence.class)
5479            protected PhonePersistence phonePersistence;
5480            @BeanReference(type = PluginSettingPersistence.class)
5481            protected PluginSettingPersistence pluginSettingPersistence;
5482            @BeanReference(type = PortletPersistence.class)
5483            protected PortletPersistence portletPersistence;
5484            @BeanReference(type = PortletItemPersistence.class)
5485            protected PortletItemPersistence portletItemPersistence;
5486            @BeanReference(type = PortletPreferencesPersistence.class)
5487            protected PortletPreferencesPersistence portletPreferencesPersistence;
5488            @BeanReference(type = RegionPersistence.class)
5489            protected RegionPersistence regionPersistence;
5490            @BeanReference(type = ReleasePersistence.class)
5491            protected ReleasePersistence releasePersistence;
5492            @BeanReference(type = ResourcePersistence.class)
5493            protected ResourcePersistence resourcePersistence;
5494            @BeanReference(type = ResourceActionPersistence.class)
5495            protected ResourceActionPersistence resourceActionPersistence;
5496            @BeanReference(type = ResourceCodePersistence.class)
5497            protected ResourceCodePersistence resourceCodePersistence;
5498            @BeanReference(type = ResourcePermissionPersistence.class)
5499            protected ResourcePermissionPersistence resourcePermissionPersistence;
5500            @BeanReference(type = RolePersistence.class)
5501            protected RolePersistence rolePersistence;
5502            @BeanReference(type = ServiceComponentPersistence.class)
5503            protected ServiceComponentPersistence serviceComponentPersistence;
5504            @BeanReference(type = ShardPersistence.class)
5505            protected ShardPersistence shardPersistence;
5506            @BeanReference(type = SubscriptionPersistence.class)
5507            protected SubscriptionPersistence subscriptionPersistence;
5508            @BeanReference(type = TicketPersistence.class)
5509            protected TicketPersistence ticketPersistence;
5510            @BeanReference(type = TeamPersistence.class)
5511            protected TeamPersistence teamPersistence;
5512            @BeanReference(type = UserPersistence.class)
5513            protected UserPersistence userPersistence;
5514            @BeanReference(type = UserGroupPersistence.class)
5515            protected UserGroupPersistence userGroupPersistence;
5516            @BeanReference(type = UserGroupGroupRolePersistence.class)
5517            protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
5518            @BeanReference(type = UserGroupRolePersistence.class)
5519            protected UserGroupRolePersistence userGroupRolePersistence;
5520            @BeanReference(type = UserIdMapperPersistence.class)
5521            protected UserIdMapperPersistence userIdMapperPersistence;
5522            @BeanReference(type = UserTrackerPersistence.class)
5523            protected UserTrackerPersistence userTrackerPersistence;
5524            @BeanReference(type = UserTrackerPathPersistence.class)
5525            protected UserTrackerPathPersistence userTrackerPathPersistence;
5526            @BeanReference(type = WebDAVPropsPersistence.class)
5527            protected WebDAVPropsPersistence webDAVPropsPersistence;
5528            @BeanReference(type = WebsitePersistence.class)
5529            protected WebsitePersistence websitePersistence;
5530            @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
5531            protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
5532            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
5533            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
5534            @BeanReference(type = DLFolderPersistence.class)
5535            protected DLFolderPersistence dlFolderPersistence;
5536            @BeanReference(type = ExpandoValuePersistence.class)
5537            protected ExpandoValuePersistence expandoValuePersistence;
5538            @BeanReference(type = JournalContentSearchPersistence.class)
5539            protected JournalContentSearchPersistence journalContentSearchPersistence;
5540            @BeanReference(type = MBMessagePersistence.class)
5541            protected MBMessagePersistence mbMessagePersistence;
5542            @BeanReference(type = RatingsStatsPersistence.class)
5543            protected RatingsStatsPersistence ratingsStatsPersistence;
5544            @BeanReference(type = TasksProposalPersistence.class)
5545            protected TasksProposalPersistence tasksProposalPersistence;
5546            private static final String _SQL_SELECT_LAYOUT = "SELECT layout FROM Layout layout";
5547            private static final String _SQL_SELECT_LAYOUT_WHERE = "SELECT layout FROM Layout layout WHERE ";
5548            private static final String _SQL_COUNT_LAYOUT = "SELECT COUNT(layout) FROM Layout layout";
5549            private static final String _SQL_COUNT_LAYOUT_WHERE = "SELECT COUNT(layout) FROM Layout layout WHERE ";
5550            private static final String _FINDER_COLUMN_UUID_UUID_1 = "layout.uuid IS NULL";
5551            private static final String _FINDER_COLUMN_UUID_UUID_2 = "layout.uuid = ?";
5552            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(layout.uuid IS NULL OR layout.uuid = ?)";
5553            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "layout.uuid IS NULL AND ";
5554            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "layout.uuid = ? AND ";
5555            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(layout.uuid IS NULL OR layout.uuid = ?) AND ";
5556            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "layout.groupId = ?";
5557            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "layout.groupId = ?";
5558            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "layout.companyId = ?";
5559            private static final String _FINDER_COLUMN_DLFOLDERID_DLFOLDERID_2 = "layout.dlFolderId = ?";
5560            private static final String _FINDER_COLUMN_ICONIMAGEID_ICONIMAGEID_2 = "layout.iconImageId = ?";
5561            private static final String _FINDER_COLUMN_G_P_GROUPID_2 = "layout.groupId = ? AND ";
5562            private static final String _FINDER_COLUMN_G_P_PRIVATELAYOUT_2 = "layout.privateLayout = ?";
5563            private static final String _FINDER_COLUMN_G_P_L_GROUPID_2 = "layout.groupId = ? AND ";
5564            private static final String _FINDER_COLUMN_G_P_L_PRIVATELAYOUT_2 = "layout.privateLayout = ? AND ";
5565            private static final String _FINDER_COLUMN_G_P_L_LAYOUTID_2 = "layout.layoutId = ?";
5566            private static final String _FINDER_COLUMN_G_P_P_GROUPID_2 = "layout.groupId = ? AND ";
5567            private static final String _FINDER_COLUMN_G_P_P_PRIVATELAYOUT_2 = "layout.privateLayout = ? AND ";
5568            private static final String _FINDER_COLUMN_G_P_P_PARENTLAYOUTID_2 = "layout.parentLayoutId = ?";
5569            private static final String _FINDER_COLUMN_G_P_F_GROUPID_2 = "layout.groupId = ? AND ";
5570            private static final String _FINDER_COLUMN_G_P_F_PRIVATELAYOUT_2 = "layout.privateLayout = ? AND ";
5571            private static final String _FINDER_COLUMN_G_P_F_FRIENDLYURL_1 = "layout.friendlyURL IS NULL";
5572            private static final String _FINDER_COLUMN_G_P_F_FRIENDLYURL_2 = "layout.friendlyURL = ?";
5573            private static final String _FINDER_COLUMN_G_P_F_FRIENDLYURL_3 = "(layout.friendlyURL IS NULL OR layout.friendlyURL = ?)";
5574            private static final String _FINDER_COLUMN_G_P_T_GROUPID_2 = "layout.groupId = ? AND ";
5575            private static final String _FINDER_COLUMN_G_P_T_PRIVATELAYOUT_2 = "layout.privateLayout = ? AND ";
5576            private static final String _FINDER_COLUMN_G_P_T_TYPE_1 = "layout.type IS NULL";
5577            private static final String _FINDER_COLUMN_G_P_T_TYPE_2 = "layout.type = ?";
5578            private static final String _FINDER_COLUMN_G_P_T_TYPE_3 = "(layout.type IS NULL OR layout.type = ?)";
5579            private static final String _FILTER_SQL_SELECT_LAYOUT_WHERE = "SELECT DISTINCT {layout.*} FROM Layout layout WHERE ";
5580            private static final String _FILTER_SQL_SELECT_LAYOUT_NO_INLINE_DISTINCT_WHERE_1 =
5581                    "SELECT {Layout.*} FROM (SELECT DISTINCT layout.plid FROM Layout layout WHERE ";
5582            private static final String _FILTER_SQL_SELECT_LAYOUT_NO_INLINE_DISTINCT_WHERE_2 =
5583                    ") TEMP_TABLE INNER JOIN Layout ON TEMP_TABLE.plid = Layout.plid";
5584            private static final String _FILTER_SQL_COUNT_LAYOUT_WHERE = "SELECT COUNT(DISTINCT layout.plid) AS COUNT_VALUE FROM Layout layout WHERE ";
5585            private static final String _FILTER_COLUMN_PK = "layout.plid";
5586            private static final String _FILTER_COLUMN_USERID = null;
5587            private static final String _FILTER_ENTITY_ALIAS = "layout";
5588            private static final String _FILTER_ENTITY_TABLE = "Layout";
5589            private static final String _ORDER_BY_ENTITY_ALIAS = "layout.";
5590            private static final String _ORDER_BY_ENTITY_TABLE = "Layout.";
5591            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Layout exists with the primary key ";
5592            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Layout exists with the key {";
5593            private static Log _log = LogFactoryUtil.getLog(LayoutPersistenceImpl.class);
5594    }