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