001    /**
002     * Copyright (c) 2000-2011 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.NoSuchLayoutSetException;
018    import com.liferay.portal.NoSuchModelException;
019    import com.liferay.portal.kernel.bean.BeanReference;
020    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
021    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
023    import com.liferay.portal.kernel.dao.orm.FinderPath;
024    import com.liferay.portal.kernel.dao.orm.Query;
025    import com.liferay.portal.kernel.dao.orm.QueryPos;
026    import com.liferay.portal.kernel.dao.orm.QueryUtil;
027    import com.liferay.portal.kernel.dao.orm.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.model.CacheModel;
038    import com.liferay.portal.model.LayoutSet;
039    import com.liferay.portal.model.ModelListener;
040    import com.liferay.portal.model.impl.LayoutSetImpl;
041    import com.liferay.portal.model.impl.LayoutSetModelImpl;
042    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
043    
044    import java.io.Serializable;
045    
046    import java.util.ArrayList;
047    import java.util.Collections;
048    import java.util.List;
049    
050    /**
051     * The persistence implementation for the layout set service.
052     *
053     * <p>
054     * Caching information and settings can be found in <code>portal.properties</code>
055     * </p>
056     *
057     * @author Brian Wing Shun Chan
058     * @see LayoutSetPersistence
059     * @see LayoutSetUtil
060     * @generated
061     */
062    public class LayoutSetPersistenceImpl extends BasePersistenceImpl<LayoutSet>
063            implements LayoutSetPersistence {
064            /*
065             * NOTE FOR DEVELOPERS:
066             *
067             * Never modify or reference this class directly. Always use {@link LayoutSetUtil} to access the layout set persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
068             */
069            public static final String FINDER_CLASS_NAME_ENTITY = LayoutSetImpl.class.getName();
070            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
071                    ".List1";
072            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
073                    ".List2";
074            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
075                            LayoutSetModelImpl.FINDER_CACHE_ENABLED, LayoutSetImpl.class,
076                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
077                            new String[] {
078                                    Long.class.getName(),
079                                    
080                            "java.lang.Integer", "java.lang.Integer",
081                                    "com.liferay.portal.kernel.util.OrderByComparator"
082                            });
083            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
084                    new FinderPath(LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
085                            LayoutSetModelImpl.FINDER_CACHE_ENABLED, LayoutSetImpl.class,
086                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
087                            new String[] { Long.class.getName() },
088                            LayoutSetModelImpl.GROUPID_COLUMN_BITMASK);
089            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
090                            LayoutSetModelImpl.FINDER_CACHE_ENABLED, Long.class,
091                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
092                            new String[] { Long.class.getName() });
093            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_LAYOUTSETPROTOTYPEUUID =
094                    new FinderPath(LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
095                            LayoutSetModelImpl.FINDER_CACHE_ENABLED, LayoutSetImpl.class,
096                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
097                            "findByLayoutSetPrototypeUuid",
098                            new String[] {
099                                    String.class.getName(),
100                                    
101                            "java.lang.Integer", "java.lang.Integer",
102                                    "com.liferay.portal.kernel.util.OrderByComparator"
103                            });
104            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LAYOUTSETPROTOTYPEUUID =
105                    new FinderPath(LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
106                            LayoutSetModelImpl.FINDER_CACHE_ENABLED, LayoutSetImpl.class,
107                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
108                            "findByLayoutSetPrototypeUuid",
109                            new String[] { String.class.getName() },
110                            LayoutSetModelImpl.LAYOUTSETPROTOTYPEUUID_COLUMN_BITMASK);
111            public static final FinderPath FINDER_PATH_COUNT_BY_LAYOUTSETPROTOTYPEUUID = new FinderPath(LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
112                            LayoutSetModelImpl.FINDER_CACHE_ENABLED, Long.class,
113                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
114                            "countByLayoutSetPrototypeUuid",
115                            new String[] { String.class.getName() });
116            public static final FinderPath FINDER_PATH_FETCH_BY_G_P = new FinderPath(LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
117                            LayoutSetModelImpl.FINDER_CACHE_ENABLED, LayoutSetImpl.class,
118                            FINDER_CLASS_NAME_ENTITY, "fetchByG_P",
119                            new String[] { Long.class.getName(), Boolean.class.getName() },
120                            LayoutSetModelImpl.GROUPID_COLUMN_BITMASK |
121                            LayoutSetModelImpl.PRIVATELAYOUT_COLUMN_BITMASK);
122            public static final FinderPath FINDER_PATH_COUNT_BY_G_P = new FinderPath(LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
123                            LayoutSetModelImpl.FINDER_CACHE_ENABLED, Long.class,
124                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P",
125                            new String[] { Long.class.getName(), Boolean.class.getName() });
126            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
127                            LayoutSetModelImpl.FINDER_CACHE_ENABLED, LayoutSetImpl.class,
128                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
129            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
130                            LayoutSetModelImpl.FINDER_CACHE_ENABLED, LayoutSetImpl.class,
131                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
132            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
133                            LayoutSetModelImpl.FINDER_CACHE_ENABLED, Long.class,
134                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
135    
136            /**
137             * Caches the layout set in the entity cache if it is enabled.
138             *
139             * @param layoutSet the layout set
140             */
141            public void cacheResult(LayoutSet layoutSet) {
142                    EntityCacheUtil.putResult(LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
143                            LayoutSetImpl.class, layoutSet.getPrimaryKey(), layoutSet);
144    
145                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P,
146                            new Object[] {
147                                    Long.valueOf(layoutSet.getGroupId()),
148                                    Boolean.valueOf(layoutSet.getPrivateLayout())
149                            }, layoutSet);
150    
151                    layoutSet.resetOriginalValues();
152            }
153    
154            /**
155             * Caches the layout sets in the entity cache if it is enabled.
156             *
157             * @param layoutSets the layout sets
158             */
159            public void cacheResult(List<LayoutSet> layoutSets) {
160                    for (LayoutSet layoutSet : layoutSets) {
161                            if (EntityCacheUtil.getResult(
162                                                    LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
163                                                    LayoutSetImpl.class, layoutSet.getPrimaryKey()) == null) {
164                                    cacheResult(layoutSet);
165                            }
166                            else {
167                                    layoutSet.resetOriginalValues();
168                            }
169                    }
170            }
171    
172            /**
173             * Clears the cache for all layout sets.
174             *
175             * <p>
176             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
177             * </p>
178             */
179            @Override
180            public void clearCache() {
181                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
182                            CacheRegistryUtil.clear(LayoutSetImpl.class.getName());
183                    }
184    
185                    EntityCacheUtil.clearCache(LayoutSetImpl.class.getName());
186    
187                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
188                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
189                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
190            }
191    
192            /**
193             * Clears the cache for the layout set.
194             *
195             * <p>
196             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
197             * </p>
198             */
199            @Override
200            public void clearCache(LayoutSet layoutSet) {
201                    EntityCacheUtil.removeResult(LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
202                            LayoutSetImpl.class, layoutSet.getPrimaryKey());
203    
204                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
205                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
206    
207                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P,
208                            new Object[] {
209                                    Long.valueOf(layoutSet.getGroupId()),
210                                    Boolean.valueOf(layoutSet.getPrivateLayout())
211                            });
212            }
213    
214            /**
215             * Creates a new layout set with the primary key. Does not add the layout set to the database.
216             *
217             * @param layoutSetId the primary key for the new layout set
218             * @return the new layout set
219             */
220            public LayoutSet create(long layoutSetId) {
221                    LayoutSet layoutSet = new LayoutSetImpl();
222    
223                    layoutSet.setNew(true);
224                    layoutSet.setPrimaryKey(layoutSetId);
225    
226                    return layoutSet;
227            }
228    
229            /**
230             * Removes the layout set with the primary key from the database. Also notifies the appropriate model listeners.
231             *
232             * @param primaryKey the primary key of the layout set
233             * @return the layout set that was removed
234             * @throws com.liferay.portal.NoSuchModelException if a layout set with the primary key could not be found
235             * @throws SystemException if a system exception occurred
236             */
237            @Override
238            public LayoutSet remove(Serializable primaryKey)
239                    throws NoSuchModelException, SystemException {
240                    return remove(((Long)primaryKey).longValue());
241            }
242    
243            /**
244             * Removes the layout set with the primary key from the database. Also notifies the appropriate model listeners.
245             *
246             * @param layoutSetId the primary key of the layout set
247             * @return the layout set that was removed
248             * @throws com.liferay.portal.NoSuchLayoutSetException if a layout set with the primary key could not be found
249             * @throws SystemException if a system exception occurred
250             */
251            public LayoutSet remove(long layoutSetId)
252                    throws NoSuchLayoutSetException, SystemException {
253                    Session session = null;
254    
255                    try {
256                            session = openSession();
257    
258                            LayoutSet layoutSet = (LayoutSet)session.get(LayoutSetImpl.class,
259                                            Long.valueOf(layoutSetId));
260    
261                            if (layoutSet == null) {
262                                    if (_log.isWarnEnabled()) {
263                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + layoutSetId);
264                                    }
265    
266                                    throw new NoSuchLayoutSetException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
267                                            layoutSetId);
268                            }
269    
270                            return layoutSetPersistence.remove(layoutSet);
271                    }
272                    catch (NoSuchLayoutSetException nsee) {
273                            throw nsee;
274                    }
275                    catch (Exception e) {
276                            throw processException(e);
277                    }
278                    finally {
279                            closeSession(session);
280                    }
281            }
282    
283            /**
284             * Removes the layout set from the database. Also notifies the appropriate model listeners.
285             *
286             * @param layoutSet the layout set
287             * @return the layout set that was removed
288             * @throws SystemException if a system exception occurred
289             */
290            @Override
291            public LayoutSet remove(LayoutSet layoutSet) throws SystemException {
292                    return super.remove(layoutSet);
293            }
294    
295            @Override
296            protected LayoutSet removeImpl(LayoutSet layoutSet)
297                    throws SystemException {
298                    layoutSet = toUnwrappedModel(layoutSet);
299    
300                    Session session = null;
301    
302                    try {
303                            session = openSession();
304    
305                            BatchSessionUtil.delete(session, layoutSet);
306                    }
307                    catch (Exception e) {
308                            throw processException(e);
309                    }
310                    finally {
311                            closeSession(session);
312                    }
313    
314                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
315                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
316    
317                    LayoutSetModelImpl layoutSetModelImpl = (LayoutSetModelImpl)layoutSet;
318    
319                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P,
320                            new Object[] {
321                                    Long.valueOf(layoutSetModelImpl.getGroupId()),
322                                    Boolean.valueOf(layoutSetModelImpl.getPrivateLayout())
323                            });
324    
325                    EntityCacheUtil.removeResult(LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
326                            LayoutSetImpl.class, layoutSet.getPrimaryKey());
327    
328                    return layoutSet;
329            }
330    
331            @Override
332            public LayoutSet updateImpl(com.liferay.portal.model.LayoutSet layoutSet,
333                    boolean merge) throws SystemException {
334                    layoutSet = toUnwrappedModel(layoutSet);
335    
336                    boolean isNew = layoutSet.isNew();
337    
338                    LayoutSetModelImpl layoutSetModelImpl = (LayoutSetModelImpl)layoutSet;
339    
340                    Session session = null;
341    
342                    try {
343                            session = openSession();
344    
345                            BatchSessionUtil.update(session, layoutSet, merge);
346    
347                            layoutSet.setNew(false);
348                    }
349                    catch (Exception e) {
350                            throw processException(e);
351                    }
352                    finally {
353                            closeSession(session);
354                    }
355    
356                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
357    
358                    if (isNew || !LayoutSetModelImpl.COLUMN_BITMASK_ENABLED) {
359                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
360                    }
361    
362                    else {
363                            if ((layoutSetModelImpl.getColumnBitmask() &
364                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
365                                    Object[] args = new Object[] {
366                                                    Long.valueOf(layoutSetModelImpl.getOriginalGroupId())
367                                            };
368    
369                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
370                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
371                                            args);
372    
373                                    args = new Object[] {
374                                                    Long.valueOf(layoutSetModelImpl.getGroupId())
375                                            };
376    
377                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
378                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
379                                            args);
380                            }
381    
382                            if ((layoutSetModelImpl.getColumnBitmask() &
383                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LAYOUTSETPROTOTYPEUUID.getColumnBitmask()) != 0) {
384                                    Object[] args = new Object[] {
385                                                    layoutSetModelImpl.getOriginalLayoutSetPrototypeUuid()
386                                            };
387    
388                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_LAYOUTSETPROTOTYPEUUID,
389                                            args);
390                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LAYOUTSETPROTOTYPEUUID,
391                                            args);
392    
393                                    args = new Object[] {
394                                                    layoutSetModelImpl.getLayoutSetPrototypeUuid()
395                                            };
396    
397                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_LAYOUTSETPROTOTYPEUUID,
398                                            args);
399                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LAYOUTSETPROTOTYPEUUID,
400                                            args);
401                            }
402                    }
403    
404                    EntityCacheUtil.putResult(LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
405                            LayoutSetImpl.class, layoutSet.getPrimaryKey(), layoutSet);
406    
407                    if (isNew) {
408                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P,
409                                    new Object[] {
410                                            Long.valueOf(layoutSet.getGroupId()),
411                                            Boolean.valueOf(layoutSet.getPrivateLayout())
412                                    }, layoutSet);
413                    }
414                    else {
415                            if ((layoutSetModelImpl.getColumnBitmask() &
416                                            FINDER_PATH_FETCH_BY_G_P.getColumnBitmask()) != 0) {
417                                    Object[] args = new Object[] {
418                                                    Long.valueOf(layoutSetModelImpl.getOriginalGroupId()),
419                                                    Boolean.valueOf(layoutSetModelImpl.getOriginalPrivateLayout())
420                                            };
421    
422                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P, args);
423                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P, args);
424    
425                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P,
426                                            new Object[] {
427                                                    Long.valueOf(layoutSet.getGroupId()),
428                                                    Boolean.valueOf(layoutSet.getPrivateLayout())
429                                            }, layoutSet);
430                            }
431                    }
432    
433                    return layoutSet;
434            }
435    
436            protected LayoutSet toUnwrappedModel(LayoutSet layoutSet) {
437                    if (layoutSet instanceof LayoutSetImpl) {
438                            return layoutSet;
439                    }
440    
441                    LayoutSetImpl layoutSetImpl = new LayoutSetImpl();
442    
443                    layoutSetImpl.setNew(layoutSet.isNew());
444                    layoutSetImpl.setPrimaryKey(layoutSet.getPrimaryKey());
445    
446                    layoutSetImpl.setLayoutSetId(layoutSet.getLayoutSetId());
447                    layoutSetImpl.setGroupId(layoutSet.getGroupId());
448                    layoutSetImpl.setCompanyId(layoutSet.getCompanyId());
449                    layoutSetImpl.setPrivateLayout(layoutSet.isPrivateLayout());
450                    layoutSetImpl.setLogo(layoutSet.isLogo());
451                    layoutSetImpl.setLogoId(layoutSet.getLogoId());
452                    layoutSetImpl.setThemeId(layoutSet.getThemeId());
453                    layoutSetImpl.setColorSchemeId(layoutSet.getColorSchemeId());
454                    layoutSetImpl.setWapThemeId(layoutSet.getWapThemeId());
455                    layoutSetImpl.setWapColorSchemeId(layoutSet.getWapColorSchemeId());
456                    layoutSetImpl.setCss(layoutSet.getCss());
457                    layoutSetImpl.setPageCount(layoutSet.getPageCount());
458                    layoutSetImpl.setSettings(layoutSet.getSettings());
459                    layoutSetImpl.setLayoutSetPrototypeUuid(layoutSet.getLayoutSetPrototypeUuid());
460                    layoutSetImpl.setLayoutSetPrototypeLinkEnabled(layoutSet.isLayoutSetPrototypeLinkEnabled());
461    
462                    return layoutSetImpl;
463            }
464    
465            /**
466             * Returns the layout set with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
467             *
468             * @param primaryKey the primary key of the layout set
469             * @return the layout set
470             * @throws com.liferay.portal.NoSuchModelException if a layout set with the primary key could not be found
471             * @throws SystemException if a system exception occurred
472             */
473            @Override
474            public LayoutSet findByPrimaryKey(Serializable primaryKey)
475                    throws NoSuchModelException, SystemException {
476                    return findByPrimaryKey(((Long)primaryKey).longValue());
477            }
478    
479            /**
480             * Returns the layout set with the primary key or throws a {@link com.liferay.portal.NoSuchLayoutSetException} if it could not be found.
481             *
482             * @param layoutSetId the primary key of the layout set
483             * @return the layout set
484             * @throws com.liferay.portal.NoSuchLayoutSetException if a layout set with the primary key could not be found
485             * @throws SystemException if a system exception occurred
486             */
487            public LayoutSet findByPrimaryKey(long layoutSetId)
488                    throws NoSuchLayoutSetException, SystemException {
489                    LayoutSet layoutSet = fetchByPrimaryKey(layoutSetId);
490    
491                    if (layoutSet == null) {
492                            if (_log.isWarnEnabled()) {
493                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + layoutSetId);
494                            }
495    
496                            throw new NoSuchLayoutSetException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
497                                    layoutSetId);
498                    }
499    
500                    return layoutSet;
501            }
502    
503            /**
504             * Returns the layout set with the primary key or returns <code>null</code> if it could not be found.
505             *
506             * @param primaryKey the primary key of the layout set
507             * @return the layout set, or <code>null</code> if a layout set with the primary key could not be found
508             * @throws SystemException if a system exception occurred
509             */
510            @Override
511            public LayoutSet fetchByPrimaryKey(Serializable primaryKey)
512                    throws SystemException {
513                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
514            }
515    
516            /**
517             * Returns the layout set with the primary key or returns <code>null</code> if it could not be found.
518             *
519             * @param layoutSetId the primary key of the layout set
520             * @return the layout set, or <code>null</code> if a layout set with the primary key could not be found
521             * @throws SystemException if a system exception occurred
522             */
523            public LayoutSet fetchByPrimaryKey(long layoutSetId)
524                    throws SystemException {
525                    LayoutSet layoutSet = (LayoutSet)EntityCacheUtil.getResult(LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
526                                    LayoutSetImpl.class, layoutSetId);
527    
528                    if (layoutSet == _nullLayoutSet) {
529                            return null;
530                    }
531    
532                    if (layoutSet == null) {
533                            Session session = null;
534    
535                            boolean hasException = false;
536    
537                            try {
538                                    session = openSession();
539    
540                                    layoutSet = (LayoutSet)session.get(LayoutSetImpl.class,
541                                                    Long.valueOf(layoutSetId));
542                            }
543                            catch (Exception e) {
544                                    hasException = true;
545    
546                                    throw processException(e);
547                            }
548                            finally {
549                                    if (layoutSet != null) {
550                                            cacheResult(layoutSet);
551                                    }
552                                    else if (!hasException) {
553                                            EntityCacheUtil.putResult(LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
554                                                    LayoutSetImpl.class, layoutSetId, _nullLayoutSet);
555                                    }
556    
557                                    closeSession(session);
558                            }
559                    }
560    
561                    return layoutSet;
562            }
563    
564            /**
565             * Returns all the layout sets where groupId = &#63;.
566             *
567             * @param groupId the group ID
568             * @return the matching layout sets
569             * @throws SystemException if a system exception occurred
570             */
571            public List<LayoutSet> findByGroupId(long groupId)
572                    throws SystemException {
573                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
574            }
575    
576            /**
577             * Returns a range of all the layout sets where groupId = &#63;.
578             *
579             * <p>
580             * 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.
581             * </p>
582             *
583             * @param groupId the group ID
584             * @param start the lower bound of the range of layout sets
585             * @param end the upper bound of the range of layout sets (not inclusive)
586             * @return the range of matching layout sets
587             * @throws SystemException if a system exception occurred
588             */
589            public List<LayoutSet> findByGroupId(long groupId, int start, int end)
590                    throws SystemException {
591                    return findByGroupId(groupId, start, end, null);
592            }
593    
594            /**
595             * Returns an ordered range of all the layout sets where groupId = &#63;.
596             *
597             * <p>
598             * 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.
599             * </p>
600             *
601             * @param groupId the group ID
602             * @param start the lower bound of the range of layout sets
603             * @param end the upper bound of the range of layout sets (not inclusive)
604             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
605             * @return the ordered range of matching layout sets
606             * @throws SystemException if a system exception occurred
607             */
608            public List<LayoutSet> findByGroupId(long groupId, int start, int end,
609                    OrderByComparator orderByComparator) throws SystemException {
610                    FinderPath finderPath = null;
611                    Object[] finderArgs = null;
612    
613                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
614                                    (orderByComparator == null)) {
615                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
616                            finderArgs = new Object[] { groupId };
617                    }
618                    else {
619                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
620                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
621                    }
622    
623                    List<LayoutSet> list = (List<LayoutSet>)FinderCacheUtil.getResult(finderPath,
624                                    finderArgs, this);
625    
626                    if (list == null) {
627                            StringBundler query = null;
628    
629                            if (orderByComparator != null) {
630                                    query = new StringBundler(3 +
631                                                    (orderByComparator.getOrderByFields().length * 3));
632                            }
633                            else {
634                                    query = new StringBundler(2);
635                            }
636    
637                            query.append(_SQL_SELECT_LAYOUTSET_WHERE);
638    
639                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
640    
641                            if (orderByComparator != null) {
642                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
643                                            orderByComparator);
644                            }
645    
646                            String sql = query.toString();
647    
648                            Session session = null;
649    
650                            try {
651                                    session = openSession();
652    
653                                    Query q = session.createQuery(sql);
654    
655                                    QueryPos qPos = QueryPos.getInstance(q);
656    
657                                    qPos.add(groupId);
658    
659                                    list = (List<LayoutSet>)QueryUtil.list(q, getDialect(), start,
660                                                    end);
661                            }
662                            catch (Exception e) {
663                                    throw processException(e);
664                            }
665                            finally {
666                                    if (list == null) {
667                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
668                                    }
669                                    else {
670                                            cacheResult(list);
671    
672                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
673                                    }
674    
675                                    closeSession(session);
676                            }
677                    }
678    
679                    return list;
680            }
681    
682            /**
683             * Returns the first layout set in the ordered set where groupId = &#63;.
684             *
685             * <p>
686             * 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.
687             * </p>
688             *
689             * @param groupId the group ID
690             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
691             * @return the first matching layout set
692             * @throws com.liferay.portal.NoSuchLayoutSetException if a matching layout set could not be found
693             * @throws SystemException if a system exception occurred
694             */
695            public LayoutSet findByGroupId_First(long groupId,
696                    OrderByComparator orderByComparator)
697                    throws NoSuchLayoutSetException, SystemException {
698                    List<LayoutSet> list = findByGroupId(groupId, 0, 1, orderByComparator);
699    
700                    if (list.isEmpty()) {
701                            StringBundler msg = new StringBundler(4);
702    
703                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
704    
705                            msg.append("groupId=");
706                            msg.append(groupId);
707    
708                            msg.append(StringPool.CLOSE_CURLY_BRACE);
709    
710                            throw new NoSuchLayoutSetException(msg.toString());
711                    }
712                    else {
713                            return list.get(0);
714                    }
715            }
716    
717            /**
718             * Returns the last layout set in the ordered set where groupId = &#63;.
719             *
720             * <p>
721             * 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.
722             * </p>
723             *
724             * @param groupId the group ID
725             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
726             * @return the last matching layout set
727             * @throws com.liferay.portal.NoSuchLayoutSetException if a matching layout set could not be found
728             * @throws SystemException if a system exception occurred
729             */
730            public LayoutSet findByGroupId_Last(long groupId,
731                    OrderByComparator orderByComparator)
732                    throws NoSuchLayoutSetException, SystemException {
733                    int count = countByGroupId(groupId);
734    
735                    List<LayoutSet> list = findByGroupId(groupId, count - 1, count,
736                                    orderByComparator);
737    
738                    if (list.isEmpty()) {
739                            StringBundler msg = new StringBundler(4);
740    
741                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
742    
743                            msg.append("groupId=");
744                            msg.append(groupId);
745    
746                            msg.append(StringPool.CLOSE_CURLY_BRACE);
747    
748                            throw new NoSuchLayoutSetException(msg.toString());
749                    }
750                    else {
751                            return list.get(0);
752                    }
753            }
754    
755            /**
756             * Returns the layout sets before and after the current layout set in the ordered set where groupId = &#63;.
757             *
758             * <p>
759             * 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.
760             * </p>
761             *
762             * @param layoutSetId the primary key of the current layout set
763             * @param groupId the group ID
764             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
765             * @return the previous, current, and next layout set
766             * @throws com.liferay.portal.NoSuchLayoutSetException if a layout set with the primary key could not be found
767             * @throws SystemException if a system exception occurred
768             */
769            public LayoutSet[] findByGroupId_PrevAndNext(long layoutSetId,
770                    long groupId, OrderByComparator orderByComparator)
771                    throws NoSuchLayoutSetException, SystemException {
772                    LayoutSet layoutSet = findByPrimaryKey(layoutSetId);
773    
774                    Session session = null;
775    
776                    try {
777                            session = openSession();
778    
779                            LayoutSet[] array = new LayoutSetImpl[3];
780    
781                            array[0] = getByGroupId_PrevAndNext(session, layoutSet, groupId,
782                                            orderByComparator, true);
783    
784                            array[1] = layoutSet;
785    
786                            array[2] = getByGroupId_PrevAndNext(session, layoutSet, groupId,
787                                            orderByComparator, false);
788    
789                            return array;
790                    }
791                    catch (Exception e) {
792                            throw processException(e);
793                    }
794                    finally {
795                            closeSession(session);
796                    }
797            }
798    
799            protected LayoutSet getByGroupId_PrevAndNext(Session session,
800                    LayoutSet layoutSet, long groupId, OrderByComparator orderByComparator,
801                    boolean previous) {
802                    StringBundler query = null;
803    
804                    if (orderByComparator != null) {
805                            query = new StringBundler(6 +
806                                            (orderByComparator.getOrderByFields().length * 6));
807                    }
808                    else {
809                            query = new StringBundler(3);
810                    }
811    
812                    query.append(_SQL_SELECT_LAYOUTSET_WHERE);
813    
814                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
815    
816                    if (orderByComparator != null) {
817                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
818    
819                            if (orderByConditionFields.length > 0) {
820                                    query.append(WHERE_AND);
821                            }
822    
823                            for (int i = 0; i < orderByConditionFields.length; i++) {
824                                    query.append(_ORDER_BY_ENTITY_ALIAS);
825                                    query.append(orderByConditionFields[i]);
826    
827                                    if ((i + 1) < orderByConditionFields.length) {
828                                            if (orderByComparator.isAscending() ^ previous) {
829                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
830                                            }
831                                            else {
832                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
833                                            }
834                                    }
835                                    else {
836                                            if (orderByComparator.isAscending() ^ previous) {
837                                                    query.append(WHERE_GREATER_THAN);
838                                            }
839                                            else {
840                                                    query.append(WHERE_LESSER_THAN);
841                                            }
842                                    }
843                            }
844    
845                            query.append(ORDER_BY_CLAUSE);
846    
847                            String[] orderByFields = orderByComparator.getOrderByFields();
848    
849                            for (int i = 0; i < orderByFields.length; i++) {
850                                    query.append(_ORDER_BY_ENTITY_ALIAS);
851                                    query.append(orderByFields[i]);
852    
853                                    if ((i + 1) < orderByFields.length) {
854                                            if (orderByComparator.isAscending() ^ previous) {
855                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
856                                            }
857                                            else {
858                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
859                                            }
860                                    }
861                                    else {
862                                            if (orderByComparator.isAscending() ^ previous) {
863                                                    query.append(ORDER_BY_ASC);
864                                            }
865                                            else {
866                                                    query.append(ORDER_BY_DESC);
867                                            }
868                                    }
869                            }
870                    }
871    
872                    String sql = query.toString();
873    
874                    Query q = session.createQuery(sql);
875    
876                    q.setFirstResult(0);
877                    q.setMaxResults(2);
878    
879                    QueryPos qPos = QueryPos.getInstance(q);
880    
881                    qPos.add(groupId);
882    
883                    if (orderByComparator != null) {
884                            Object[] values = orderByComparator.getOrderByConditionValues(layoutSet);
885    
886                            for (Object value : values) {
887                                    qPos.add(value);
888                            }
889                    }
890    
891                    List<LayoutSet> list = q.list();
892    
893                    if (list.size() == 2) {
894                            return list.get(1);
895                    }
896                    else {
897                            return null;
898                    }
899            }
900    
901            /**
902             * Returns all the layout sets where layoutSetPrototypeUuid = &#63;.
903             *
904             * @param layoutSetPrototypeUuid the layout set prototype uuid
905             * @return the matching layout sets
906             * @throws SystemException if a system exception occurred
907             */
908            public List<LayoutSet> findByLayoutSetPrototypeUuid(
909                    String layoutSetPrototypeUuid) throws SystemException {
910                    return findByLayoutSetPrototypeUuid(layoutSetPrototypeUuid,
911                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
912            }
913    
914            /**
915             * Returns a range of all the layout sets where layoutSetPrototypeUuid = &#63;.
916             *
917             * <p>
918             * 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.
919             * </p>
920             *
921             * @param layoutSetPrototypeUuid the layout set prototype uuid
922             * @param start the lower bound of the range of layout sets
923             * @param end the upper bound of the range of layout sets (not inclusive)
924             * @return the range of matching layout sets
925             * @throws SystemException if a system exception occurred
926             */
927            public List<LayoutSet> findByLayoutSetPrototypeUuid(
928                    String layoutSetPrototypeUuid, int start, int end)
929                    throws SystemException {
930                    return findByLayoutSetPrototypeUuid(layoutSetPrototypeUuid, start, end,
931                            null);
932            }
933    
934            /**
935             * Returns an ordered range of all the layout sets where layoutSetPrototypeUuid = &#63;.
936             *
937             * <p>
938             * 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.
939             * </p>
940             *
941             * @param layoutSetPrototypeUuid the layout set prototype uuid
942             * @param start the lower bound of the range of layout sets
943             * @param end the upper bound of the range of layout sets (not inclusive)
944             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
945             * @return the ordered range of matching layout sets
946             * @throws SystemException if a system exception occurred
947             */
948            public List<LayoutSet> findByLayoutSetPrototypeUuid(
949                    String layoutSetPrototypeUuid, int start, int end,
950                    OrderByComparator orderByComparator) throws SystemException {
951                    FinderPath finderPath = null;
952                    Object[] finderArgs = null;
953    
954                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
955                                    (orderByComparator == null)) {
956                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LAYOUTSETPROTOTYPEUUID;
957                            finderArgs = new Object[] { layoutSetPrototypeUuid };
958                    }
959                    else {
960                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_LAYOUTSETPROTOTYPEUUID;
961                            finderArgs = new Object[] {
962                                            layoutSetPrototypeUuid,
963                                            
964                                            start, end, orderByComparator
965                                    };
966                    }
967    
968                    List<LayoutSet> list = (List<LayoutSet>)FinderCacheUtil.getResult(finderPath,
969                                    finderArgs, this);
970    
971                    if (list == null) {
972                            StringBundler query = null;
973    
974                            if (orderByComparator != null) {
975                                    query = new StringBundler(3 +
976                                                    (orderByComparator.getOrderByFields().length * 3));
977                            }
978                            else {
979                                    query = new StringBundler(2);
980                            }
981    
982                            query.append(_SQL_SELECT_LAYOUTSET_WHERE);
983    
984                            if (layoutSetPrototypeUuid == null) {
985                                    query.append(_FINDER_COLUMN_LAYOUTSETPROTOTYPEUUID_LAYOUTSETPROTOTYPEUUID_1);
986                            }
987                            else {
988                                    if (layoutSetPrototypeUuid.equals(StringPool.BLANK)) {
989                                            query.append(_FINDER_COLUMN_LAYOUTSETPROTOTYPEUUID_LAYOUTSETPROTOTYPEUUID_3);
990                                    }
991                                    else {
992                                            query.append(_FINDER_COLUMN_LAYOUTSETPROTOTYPEUUID_LAYOUTSETPROTOTYPEUUID_2);
993                                    }
994                            }
995    
996                            if (orderByComparator != null) {
997                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
998                                            orderByComparator);
999                            }
1000    
1001                            String sql = query.toString();
1002    
1003                            Session session = null;
1004    
1005                            try {
1006                                    session = openSession();
1007    
1008                                    Query q = session.createQuery(sql);
1009    
1010                                    QueryPos qPos = QueryPos.getInstance(q);
1011    
1012                                    if (layoutSetPrototypeUuid != null) {
1013                                            qPos.add(layoutSetPrototypeUuid);
1014                                    }
1015    
1016                                    list = (List<LayoutSet>)QueryUtil.list(q, getDialect(), start,
1017                                                    end);
1018                            }
1019                            catch (Exception e) {
1020                                    throw processException(e);
1021                            }
1022                            finally {
1023                                    if (list == null) {
1024                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1025                                    }
1026                                    else {
1027                                            cacheResult(list);
1028    
1029                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1030                                    }
1031    
1032                                    closeSession(session);
1033                            }
1034                    }
1035    
1036                    return list;
1037            }
1038    
1039            /**
1040             * Returns the first layout set in the ordered set where layoutSetPrototypeUuid = &#63;.
1041             *
1042             * <p>
1043             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1044             * </p>
1045             *
1046             * @param layoutSetPrototypeUuid the layout set prototype uuid
1047             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1048             * @return the first matching layout set
1049             * @throws com.liferay.portal.NoSuchLayoutSetException if a matching layout set could not be found
1050             * @throws SystemException if a system exception occurred
1051             */
1052            public LayoutSet findByLayoutSetPrototypeUuid_First(
1053                    String layoutSetPrototypeUuid, OrderByComparator orderByComparator)
1054                    throws NoSuchLayoutSetException, SystemException {
1055                    List<LayoutSet> list = findByLayoutSetPrototypeUuid(layoutSetPrototypeUuid,
1056                                    0, 1, orderByComparator);
1057    
1058                    if (list.isEmpty()) {
1059                            StringBundler msg = new StringBundler(4);
1060    
1061                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1062    
1063                            msg.append("layoutSetPrototypeUuid=");
1064                            msg.append(layoutSetPrototypeUuid);
1065    
1066                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1067    
1068                            throw new NoSuchLayoutSetException(msg.toString());
1069                    }
1070                    else {
1071                            return list.get(0);
1072                    }
1073            }
1074    
1075            /**
1076             * Returns the last layout set in the ordered set where layoutSetPrototypeUuid = &#63;.
1077             *
1078             * <p>
1079             * 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.
1080             * </p>
1081             *
1082             * @param layoutSetPrototypeUuid the layout set prototype uuid
1083             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1084             * @return the last matching layout set
1085             * @throws com.liferay.portal.NoSuchLayoutSetException if a matching layout set could not be found
1086             * @throws SystemException if a system exception occurred
1087             */
1088            public LayoutSet findByLayoutSetPrototypeUuid_Last(
1089                    String layoutSetPrototypeUuid, OrderByComparator orderByComparator)
1090                    throws NoSuchLayoutSetException, SystemException {
1091                    int count = countByLayoutSetPrototypeUuid(layoutSetPrototypeUuid);
1092    
1093                    List<LayoutSet> list = findByLayoutSetPrototypeUuid(layoutSetPrototypeUuid,
1094                                    count - 1, count, orderByComparator);
1095    
1096                    if (list.isEmpty()) {
1097                            StringBundler msg = new StringBundler(4);
1098    
1099                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1100    
1101                            msg.append("layoutSetPrototypeUuid=");
1102                            msg.append(layoutSetPrototypeUuid);
1103    
1104                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1105    
1106                            throw new NoSuchLayoutSetException(msg.toString());
1107                    }
1108                    else {
1109                            return list.get(0);
1110                    }
1111            }
1112    
1113            /**
1114             * Returns the layout sets before and after the current layout set in the ordered set where layoutSetPrototypeUuid = &#63;.
1115             *
1116             * <p>
1117             * 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.
1118             * </p>
1119             *
1120             * @param layoutSetId the primary key of the current layout set
1121             * @param layoutSetPrototypeUuid the layout set prototype uuid
1122             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1123             * @return the previous, current, and next layout set
1124             * @throws com.liferay.portal.NoSuchLayoutSetException if a layout set with the primary key could not be found
1125             * @throws SystemException if a system exception occurred
1126             */
1127            public LayoutSet[] findByLayoutSetPrototypeUuid_PrevAndNext(
1128                    long layoutSetId, String layoutSetPrototypeUuid,
1129                    OrderByComparator orderByComparator)
1130                    throws NoSuchLayoutSetException, SystemException {
1131                    LayoutSet layoutSet = findByPrimaryKey(layoutSetId);
1132    
1133                    Session session = null;
1134    
1135                    try {
1136                            session = openSession();
1137    
1138                            LayoutSet[] array = new LayoutSetImpl[3];
1139    
1140                            array[0] = getByLayoutSetPrototypeUuid_PrevAndNext(session,
1141                                            layoutSet, layoutSetPrototypeUuid, orderByComparator, true);
1142    
1143                            array[1] = layoutSet;
1144    
1145                            array[2] = getByLayoutSetPrototypeUuid_PrevAndNext(session,
1146                                            layoutSet, layoutSetPrototypeUuid, orderByComparator, false);
1147    
1148                            return array;
1149                    }
1150                    catch (Exception e) {
1151                            throw processException(e);
1152                    }
1153                    finally {
1154                            closeSession(session);
1155                    }
1156            }
1157    
1158            protected LayoutSet getByLayoutSetPrototypeUuid_PrevAndNext(
1159                    Session session, LayoutSet layoutSet, String layoutSetPrototypeUuid,
1160                    OrderByComparator orderByComparator, boolean previous) {
1161                    StringBundler query = null;
1162    
1163                    if (orderByComparator != null) {
1164                            query = new StringBundler(6 +
1165                                            (orderByComparator.getOrderByFields().length * 6));
1166                    }
1167                    else {
1168                            query = new StringBundler(3);
1169                    }
1170    
1171                    query.append(_SQL_SELECT_LAYOUTSET_WHERE);
1172    
1173                    if (layoutSetPrototypeUuid == null) {
1174                            query.append(_FINDER_COLUMN_LAYOUTSETPROTOTYPEUUID_LAYOUTSETPROTOTYPEUUID_1);
1175                    }
1176                    else {
1177                            if (layoutSetPrototypeUuid.equals(StringPool.BLANK)) {
1178                                    query.append(_FINDER_COLUMN_LAYOUTSETPROTOTYPEUUID_LAYOUTSETPROTOTYPEUUID_3);
1179                            }
1180                            else {
1181                                    query.append(_FINDER_COLUMN_LAYOUTSETPROTOTYPEUUID_LAYOUTSETPROTOTYPEUUID_2);
1182                            }
1183                    }
1184    
1185                    if (orderByComparator != null) {
1186                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1187    
1188                            if (orderByConditionFields.length > 0) {
1189                                    query.append(WHERE_AND);
1190                            }
1191    
1192                            for (int i = 0; i < orderByConditionFields.length; i++) {
1193                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1194                                    query.append(orderByConditionFields[i]);
1195    
1196                                    if ((i + 1) < orderByConditionFields.length) {
1197                                            if (orderByComparator.isAscending() ^ previous) {
1198                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1199                                            }
1200                                            else {
1201                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1202                                            }
1203                                    }
1204                                    else {
1205                                            if (orderByComparator.isAscending() ^ previous) {
1206                                                    query.append(WHERE_GREATER_THAN);
1207                                            }
1208                                            else {
1209                                                    query.append(WHERE_LESSER_THAN);
1210                                            }
1211                                    }
1212                            }
1213    
1214                            query.append(ORDER_BY_CLAUSE);
1215    
1216                            String[] orderByFields = orderByComparator.getOrderByFields();
1217    
1218                            for (int i = 0; i < orderByFields.length; i++) {
1219                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1220                                    query.append(orderByFields[i]);
1221    
1222                                    if ((i + 1) < orderByFields.length) {
1223                                            if (orderByComparator.isAscending() ^ previous) {
1224                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1225                                            }
1226                                            else {
1227                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1228                                            }
1229                                    }
1230                                    else {
1231                                            if (orderByComparator.isAscending() ^ previous) {
1232                                                    query.append(ORDER_BY_ASC);
1233                                            }
1234                                            else {
1235                                                    query.append(ORDER_BY_DESC);
1236                                            }
1237                                    }
1238                            }
1239                    }
1240    
1241                    String sql = query.toString();
1242    
1243                    Query q = session.createQuery(sql);
1244    
1245                    q.setFirstResult(0);
1246                    q.setMaxResults(2);
1247    
1248                    QueryPos qPos = QueryPos.getInstance(q);
1249    
1250                    if (layoutSetPrototypeUuid != null) {
1251                            qPos.add(layoutSetPrototypeUuid);
1252                    }
1253    
1254                    if (orderByComparator != null) {
1255                            Object[] values = orderByComparator.getOrderByConditionValues(layoutSet);
1256    
1257                            for (Object value : values) {
1258                                    qPos.add(value);
1259                            }
1260                    }
1261    
1262                    List<LayoutSet> list = q.list();
1263    
1264                    if (list.size() == 2) {
1265                            return list.get(1);
1266                    }
1267                    else {
1268                            return null;
1269                    }
1270            }
1271    
1272            /**
1273             * Returns the layout set where groupId = &#63; and privateLayout = &#63; or throws a {@link com.liferay.portal.NoSuchLayoutSetException} if it could not be found.
1274             *
1275             * @param groupId the group ID
1276             * @param privateLayout the private layout
1277             * @return the matching layout set
1278             * @throws com.liferay.portal.NoSuchLayoutSetException if a matching layout set could not be found
1279             * @throws SystemException if a system exception occurred
1280             */
1281            public LayoutSet findByG_P(long groupId, boolean privateLayout)
1282                    throws NoSuchLayoutSetException, SystemException {
1283                    LayoutSet layoutSet = fetchByG_P(groupId, privateLayout);
1284    
1285                    if (layoutSet == null) {
1286                            StringBundler msg = new StringBundler(6);
1287    
1288                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1289    
1290                            msg.append("groupId=");
1291                            msg.append(groupId);
1292    
1293                            msg.append(", privateLayout=");
1294                            msg.append(privateLayout);
1295    
1296                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1297    
1298                            if (_log.isWarnEnabled()) {
1299                                    _log.warn(msg.toString());
1300                            }
1301    
1302                            throw new NoSuchLayoutSetException(msg.toString());
1303                    }
1304    
1305                    return layoutSet;
1306            }
1307    
1308            /**
1309             * Returns the layout set where groupId = &#63; and privateLayout = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
1310             *
1311             * @param groupId the group ID
1312             * @param privateLayout the private layout
1313             * @return the matching layout set, or <code>null</code> if a matching layout set could not be found
1314             * @throws SystemException if a system exception occurred
1315             */
1316            public LayoutSet fetchByG_P(long groupId, boolean privateLayout)
1317                    throws SystemException {
1318                    return fetchByG_P(groupId, privateLayout, true);
1319            }
1320    
1321            /**
1322             * Returns the layout set where groupId = &#63; and privateLayout = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
1323             *
1324             * @param groupId the group ID
1325             * @param privateLayout the private layout
1326             * @param retrieveFromCache whether to use the finder cache
1327             * @return the matching layout set, or <code>null</code> if a matching layout set could not be found
1328             * @throws SystemException if a system exception occurred
1329             */
1330            public LayoutSet fetchByG_P(long groupId, boolean privateLayout,
1331                    boolean retrieveFromCache) throws SystemException {
1332                    Object[] finderArgs = new Object[] { groupId, privateLayout };
1333    
1334                    Object result = null;
1335    
1336                    if (retrieveFromCache) {
1337                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_P,
1338                                            finderArgs, this);
1339                    }
1340    
1341                    if (result == null) {
1342                            StringBundler query = new StringBundler(3);
1343    
1344                            query.append(_SQL_SELECT_LAYOUTSET_WHERE);
1345    
1346                            query.append(_FINDER_COLUMN_G_P_GROUPID_2);
1347    
1348                            query.append(_FINDER_COLUMN_G_P_PRIVATELAYOUT_2);
1349    
1350                            String sql = query.toString();
1351    
1352                            Session session = null;
1353    
1354                            try {
1355                                    session = openSession();
1356    
1357                                    Query q = session.createQuery(sql);
1358    
1359                                    QueryPos qPos = QueryPos.getInstance(q);
1360    
1361                                    qPos.add(groupId);
1362    
1363                                    qPos.add(privateLayout);
1364    
1365                                    List<LayoutSet> list = q.list();
1366    
1367                                    result = list;
1368    
1369                                    LayoutSet layoutSet = null;
1370    
1371                                    if (list.isEmpty()) {
1372                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P,
1373                                                    finderArgs, list);
1374                                    }
1375                                    else {
1376                                            layoutSet = list.get(0);
1377    
1378                                            cacheResult(layoutSet);
1379    
1380                                            if ((layoutSet.getGroupId() != groupId) ||
1381                                                            (layoutSet.getPrivateLayout() != privateLayout)) {
1382                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P,
1383                                                            finderArgs, layoutSet);
1384                                            }
1385                                    }
1386    
1387                                    return layoutSet;
1388                            }
1389                            catch (Exception e) {
1390                                    throw processException(e);
1391                            }
1392                            finally {
1393                                    if (result == null) {
1394                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P,
1395                                                    finderArgs);
1396                                    }
1397    
1398                                    closeSession(session);
1399                            }
1400                    }
1401                    else {
1402                            if (result instanceof List<?>) {
1403                                    return null;
1404                            }
1405                            else {
1406                                    return (LayoutSet)result;
1407                            }
1408                    }
1409            }
1410    
1411            /**
1412             * Returns all the layout sets.
1413             *
1414             * @return the layout sets
1415             * @throws SystemException if a system exception occurred
1416             */
1417            public List<LayoutSet> findAll() throws SystemException {
1418                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1419            }
1420    
1421            /**
1422             * Returns a range of all the layout sets.
1423             *
1424             * <p>
1425             * 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.
1426             * </p>
1427             *
1428             * @param start the lower bound of the range of layout sets
1429             * @param end the upper bound of the range of layout sets (not inclusive)
1430             * @return the range of layout sets
1431             * @throws SystemException if a system exception occurred
1432             */
1433            public List<LayoutSet> findAll(int start, int end)
1434                    throws SystemException {
1435                    return findAll(start, end, null);
1436            }
1437    
1438            /**
1439             * Returns an ordered range of all the layout sets.
1440             *
1441             * <p>
1442             * 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.
1443             * </p>
1444             *
1445             * @param start the lower bound of the range of layout sets
1446             * @param end the upper bound of the range of layout sets (not inclusive)
1447             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1448             * @return the ordered range of layout sets
1449             * @throws SystemException if a system exception occurred
1450             */
1451            public List<LayoutSet> findAll(int start, int end,
1452                    OrderByComparator orderByComparator) throws SystemException {
1453                    FinderPath finderPath = null;
1454                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
1455    
1456                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1457                                    (orderByComparator == null)) {
1458                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1459                            finderArgs = FINDER_ARGS_EMPTY;
1460                    }
1461                    else {
1462                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1463                            finderArgs = new Object[] { start, end, orderByComparator };
1464                    }
1465    
1466                    List<LayoutSet> list = (List<LayoutSet>)FinderCacheUtil.getResult(finderPath,
1467                                    finderArgs, this);
1468    
1469                    if (list == null) {
1470                            StringBundler query = null;
1471                            String sql = null;
1472    
1473                            if (orderByComparator != null) {
1474                                    query = new StringBundler(2 +
1475                                                    (orderByComparator.getOrderByFields().length * 3));
1476    
1477                                    query.append(_SQL_SELECT_LAYOUTSET);
1478    
1479                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1480                                            orderByComparator);
1481    
1482                                    sql = query.toString();
1483                            }
1484                            else {
1485                                    sql = _SQL_SELECT_LAYOUTSET;
1486                            }
1487    
1488                            Session session = null;
1489    
1490                            try {
1491                                    session = openSession();
1492    
1493                                    Query q = session.createQuery(sql);
1494    
1495                                    if (orderByComparator == null) {
1496                                            list = (List<LayoutSet>)QueryUtil.list(q, getDialect(),
1497                                                            start, end, false);
1498    
1499                                            Collections.sort(list);
1500                                    }
1501                                    else {
1502                                            list = (List<LayoutSet>)QueryUtil.list(q, getDialect(),
1503                                                            start, end);
1504                                    }
1505                            }
1506                            catch (Exception e) {
1507                                    throw processException(e);
1508                            }
1509                            finally {
1510                                    if (list == null) {
1511                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1512                                    }
1513                                    else {
1514                                            cacheResult(list);
1515    
1516                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1517                                    }
1518    
1519                                    closeSession(session);
1520                            }
1521                    }
1522    
1523                    return list;
1524            }
1525    
1526            /**
1527             * Removes all the layout sets where groupId = &#63; from the database.
1528             *
1529             * @param groupId the group ID
1530             * @throws SystemException if a system exception occurred
1531             */
1532            public void removeByGroupId(long groupId) throws SystemException {
1533                    for (LayoutSet layoutSet : findByGroupId(groupId)) {
1534                            layoutSetPersistence.remove(layoutSet);
1535                    }
1536            }
1537    
1538            /**
1539             * Removes all the layout sets where layoutSetPrototypeUuid = &#63; from the database.
1540             *
1541             * @param layoutSetPrototypeUuid the layout set prototype uuid
1542             * @throws SystemException if a system exception occurred
1543             */
1544            public void removeByLayoutSetPrototypeUuid(String layoutSetPrototypeUuid)
1545                    throws SystemException {
1546                    for (LayoutSet layoutSet : findByLayoutSetPrototypeUuid(
1547                                    layoutSetPrototypeUuid)) {
1548                            layoutSetPersistence.remove(layoutSet);
1549                    }
1550            }
1551    
1552            /**
1553             * Removes the layout set where groupId = &#63; and privateLayout = &#63; from the database.
1554             *
1555             * @param groupId the group ID
1556             * @param privateLayout the private layout
1557             * @throws SystemException if a system exception occurred
1558             */
1559            public void removeByG_P(long groupId, boolean privateLayout)
1560                    throws NoSuchLayoutSetException, SystemException {
1561                    LayoutSet layoutSet = findByG_P(groupId, privateLayout);
1562    
1563                    layoutSetPersistence.remove(layoutSet);
1564            }
1565    
1566            /**
1567             * Removes all the layout sets from the database.
1568             *
1569             * @throws SystemException if a system exception occurred
1570             */
1571            public void removeAll() throws SystemException {
1572                    for (LayoutSet layoutSet : findAll()) {
1573                            layoutSetPersistence.remove(layoutSet);
1574                    }
1575            }
1576    
1577            /**
1578             * Returns the number of layout sets where groupId = &#63;.
1579             *
1580             * @param groupId the group ID
1581             * @return the number of matching layout sets
1582             * @throws SystemException if a system exception occurred
1583             */
1584            public int countByGroupId(long groupId) throws SystemException {
1585                    Object[] finderArgs = new Object[] { groupId };
1586    
1587                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
1588                                    finderArgs, this);
1589    
1590                    if (count == null) {
1591                            StringBundler query = new StringBundler(2);
1592    
1593                            query.append(_SQL_COUNT_LAYOUTSET_WHERE);
1594    
1595                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1596    
1597                            String sql = query.toString();
1598    
1599                            Session session = null;
1600    
1601                            try {
1602                                    session = openSession();
1603    
1604                                    Query q = session.createQuery(sql);
1605    
1606                                    QueryPos qPos = QueryPos.getInstance(q);
1607    
1608                                    qPos.add(groupId);
1609    
1610                                    count = (Long)q.uniqueResult();
1611                            }
1612                            catch (Exception e) {
1613                                    throw processException(e);
1614                            }
1615                            finally {
1616                                    if (count == null) {
1617                                            count = Long.valueOf(0);
1618                                    }
1619    
1620                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
1621                                            finderArgs, count);
1622    
1623                                    closeSession(session);
1624                            }
1625                    }
1626    
1627                    return count.intValue();
1628            }
1629    
1630            /**
1631             * Returns the number of layout sets where layoutSetPrototypeUuid = &#63;.
1632             *
1633             * @param layoutSetPrototypeUuid the layout set prototype uuid
1634             * @return the number of matching layout sets
1635             * @throws SystemException if a system exception occurred
1636             */
1637            public int countByLayoutSetPrototypeUuid(String layoutSetPrototypeUuid)
1638                    throws SystemException {
1639                    Object[] finderArgs = new Object[] { layoutSetPrototypeUuid };
1640    
1641                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_LAYOUTSETPROTOTYPEUUID,
1642                                    finderArgs, this);
1643    
1644                    if (count == null) {
1645                            StringBundler query = new StringBundler(2);
1646    
1647                            query.append(_SQL_COUNT_LAYOUTSET_WHERE);
1648    
1649                            if (layoutSetPrototypeUuid == null) {
1650                                    query.append(_FINDER_COLUMN_LAYOUTSETPROTOTYPEUUID_LAYOUTSETPROTOTYPEUUID_1);
1651                            }
1652                            else {
1653                                    if (layoutSetPrototypeUuid.equals(StringPool.BLANK)) {
1654                                            query.append(_FINDER_COLUMN_LAYOUTSETPROTOTYPEUUID_LAYOUTSETPROTOTYPEUUID_3);
1655                                    }
1656                                    else {
1657                                            query.append(_FINDER_COLUMN_LAYOUTSETPROTOTYPEUUID_LAYOUTSETPROTOTYPEUUID_2);
1658                                    }
1659                            }
1660    
1661                            String sql = query.toString();
1662    
1663                            Session session = null;
1664    
1665                            try {
1666                                    session = openSession();
1667    
1668                                    Query q = session.createQuery(sql);
1669    
1670                                    QueryPos qPos = QueryPos.getInstance(q);
1671    
1672                                    if (layoutSetPrototypeUuid != null) {
1673                                            qPos.add(layoutSetPrototypeUuid);
1674                                    }
1675    
1676                                    count = (Long)q.uniqueResult();
1677                            }
1678                            catch (Exception e) {
1679                                    throw processException(e);
1680                            }
1681                            finally {
1682                                    if (count == null) {
1683                                            count = Long.valueOf(0);
1684                                    }
1685    
1686                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_LAYOUTSETPROTOTYPEUUID,
1687                                            finderArgs, count);
1688    
1689                                    closeSession(session);
1690                            }
1691                    }
1692    
1693                    return count.intValue();
1694            }
1695    
1696            /**
1697             * Returns the number of layout sets where groupId = &#63; and privateLayout = &#63;.
1698             *
1699             * @param groupId the group ID
1700             * @param privateLayout the private layout
1701             * @return the number of matching layout sets
1702             * @throws SystemException if a system exception occurred
1703             */
1704            public int countByG_P(long groupId, boolean privateLayout)
1705                    throws SystemException {
1706                    Object[] finderArgs = new Object[] { groupId, privateLayout };
1707    
1708                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_P,
1709                                    finderArgs, this);
1710    
1711                    if (count == null) {
1712                            StringBundler query = new StringBundler(3);
1713    
1714                            query.append(_SQL_COUNT_LAYOUTSET_WHERE);
1715    
1716                            query.append(_FINDER_COLUMN_G_P_GROUPID_2);
1717    
1718                            query.append(_FINDER_COLUMN_G_P_PRIVATELAYOUT_2);
1719    
1720                            String sql = query.toString();
1721    
1722                            Session session = null;
1723    
1724                            try {
1725                                    session = openSession();
1726    
1727                                    Query q = session.createQuery(sql);
1728    
1729                                    QueryPos qPos = QueryPos.getInstance(q);
1730    
1731                                    qPos.add(groupId);
1732    
1733                                    qPos.add(privateLayout);
1734    
1735                                    count = (Long)q.uniqueResult();
1736                            }
1737                            catch (Exception e) {
1738                                    throw processException(e);
1739                            }
1740                            finally {
1741                                    if (count == null) {
1742                                            count = Long.valueOf(0);
1743                                    }
1744    
1745                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_P, finderArgs,
1746                                            count);
1747    
1748                                    closeSession(session);
1749                            }
1750                    }
1751    
1752                    return count.intValue();
1753            }
1754    
1755            /**
1756             * Returns the number of layout sets.
1757             *
1758             * @return the number of layout sets
1759             * @throws SystemException if a system exception occurred
1760             */
1761            public int countAll() throws SystemException {
1762                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1763                                    FINDER_ARGS_EMPTY, this);
1764    
1765                    if (count == null) {
1766                            Session session = null;
1767    
1768                            try {
1769                                    session = openSession();
1770    
1771                                    Query q = session.createQuery(_SQL_COUNT_LAYOUTSET);
1772    
1773                                    count = (Long)q.uniqueResult();
1774                            }
1775                            catch (Exception e) {
1776                                    throw processException(e);
1777                            }
1778                            finally {
1779                                    if (count == null) {
1780                                            count = Long.valueOf(0);
1781                                    }
1782    
1783                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1784                                            FINDER_ARGS_EMPTY, count);
1785    
1786                                    closeSession(session);
1787                            }
1788                    }
1789    
1790                    return count.intValue();
1791            }
1792    
1793            /**
1794             * Initializes the layout set persistence.
1795             */
1796            public void afterPropertiesSet() {
1797                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1798                                            com.liferay.portal.util.PropsUtil.get(
1799                                                    "value.object.listener.com.liferay.portal.model.LayoutSet")));
1800    
1801                    if (listenerClassNames.length > 0) {
1802                            try {
1803                                    List<ModelListener<LayoutSet>> listenersList = new ArrayList<ModelListener<LayoutSet>>();
1804    
1805                                    for (String listenerClassName : listenerClassNames) {
1806                                            listenersList.add((ModelListener<LayoutSet>)InstanceFactory.newInstance(
1807                                                            listenerClassName));
1808                                    }
1809    
1810                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1811                            }
1812                            catch (Exception e) {
1813                                    _log.error(e);
1814                            }
1815                    }
1816            }
1817    
1818            public void destroy() {
1819                    EntityCacheUtil.removeCache(LayoutSetImpl.class.getName());
1820                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1821                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1822            }
1823    
1824            @BeanReference(type = AccountPersistence.class)
1825            protected AccountPersistence accountPersistence;
1826            @BeanReference(type = AddressPersistence.class)
1827            protected AddressPersistence addressPersistence;
1828            @BeanReference(type = BrowserTrackerPersistence.class)
1829            protected BrowserTrackerPersistence browserTrackerPersistence;
1830            @BeanReference(type = ClassNamePersistence.class)
1831            protected ClassNamePersistence classNamePersistence;
1832            @BeanReference(type = ClusterGroupPersistence.class)
1833            protected ClusterGroupPersistence clusterGroupPersistence;
1834            @BeanReference(type = CompanyPersistence.class)
1835            protected CompanyPersistence companyPersistence;
1836            @BeanReference(type = ContactPersistence.class)
1837            protected ContactPersistence contactPersistence;
1838            @BeanReference(type = CountryPersistence.class)
1839            protected CountryPersistence countryPersistence;
1840            @BeanReference(type = EmailAddressPersistence.class)
1841            protected EmailAddressPersistence emailAddressPersistence;
1842            @BeanReference(type = GroupPersistence.class)
1843            protected GroupPersistence groupPersistence;
1844            @BeanReference(type = ImagePersistence.class)
1845            protected ImagePersistence imagePersistence;
1846            @BeanReference(type = LayoutPersistence.class)
1847            protected LayoutPersistence layoutPersistence;
1848            @BeanReference(type = LayoutBranchPersistence.class)
1849            protected LayoutBranchPersistence layoutBranchPersistence;
1850            @BeanReference(type = LayoutPrototypePersistence.class)
1851            protected LayoutPrototypePersistence layoutPrototypePersistence;
1852            @BeanReference(type = LayoutRevisionPersistence.class)
1853            protected LayoutRevisionPersistence layoutRevisionPersistence;
1854            @BeanReference(type = LayoutSetPersistence.class)
1855            protected LayoutSetPersistence layoutSetPersistence;
1856            @BeanReference(type = LayoutSetBranchPersistence.class)
1857            protected LayoutSetBranchPersistence layoutSetBranchPersistence;
1858            @BeanReference(type = LayoutSetPrototypePersistence.class)
1859            protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
1860            @BeanReference(type = ListTypePersistence.class)
1861            protected ListTypePersistence listTypePersistence;
1862            @BeanReference(type = LockPersistence.class)
1863            protected LockPersistence lockPersistence;
1864            @BeanReference(type = MembershipRequestPersistence.class)
1865            protected MembershipRequestPersistence membershipRequestPersistence;
1866            @BeanReference(type = OrganizationPersistence.class)
1867            protected OrganizationPersistence organizationPersistence;
1868            @BeanReference(type = OrgGroupPermissionPersistence.class)
1869            protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1870            @BeanReference(type = OrgGroupRolePersistence.class)
1871            protected OrgGroupRolePersistence orgGroupRolePersistence;
1872            @BeanReference(type = OrgLaborPersistence.class)
1873            protected OrgLaborPersistence orgLaborPersistence;
1874            @BeanReference(type = PasswordPolicyPersistence.class)
1875            protected PasswordPolicyPersistence passwordPolicyPersistence;
1876            @BeanReference(type = PasswordPolicyRelPersistence.class)
1877            protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1878            @BeanReference(type = PasswordTrackerPersistence.class)
1879            protected PasswordTrackerPersistence passwordTrackerPersistence;
1880            @BeanReference(type = PermissionPersistence.class)
1881            protected PermissionPersistence permissionPersistence;
1882            @BeanReference(type = PhonePersistence.class)
1883            protected PhonePersistence phonePersistence;
1884            @BeanReference(type = PluginSettingPersistence.class)
1885            protected PluginSettingPersistence pluginSettingPersistence;
1886            @BeanReference(type = PortalPreferencesPersistence.class)
1887            protected PortalPreferencesPersistence portalPreferencesPersistence;
1888            @BeanReference(type = PortletPersistence.class)
1889            protected PortletPersistence portletPersistence;
1890            @BeanReference(type = PortletItemPersistence.class)
1891            protected PortletItemPersistence portletItemPersistence;
1892            @BeanReference(type = PortletPreferencesPersistence.class)
1893            protected PortletPreferencesPersistence portletPreferencesPersistence;
1894            @BeanReference(type = RegionPersistence.class)
1895            protected RegionPersistence regionPersistence;
1896            @BeanReference(type = ReleasePersistence.class)
1897            protected ReleasePersistence releasePersistence;
1898            @BeanReference(type = RepositoryPersistence.class)
1899            protected RepositoryPersistence repositoryPersistence;
1900            @BeanReference(type = RepositoryEntryPersistence.class)
1901            protected RepositoryEntryPersistence repositoryEntryPersistence;
1902            @BeanReference(type = ResourcePersistence.class)
1903            protected ResourcePersistence resourcePersistence;
1904            @BeanReference(type = ResourceActionPersistence.class)
1905            protected ResourceActionPersistence resourceActionPersistence;
1906            @BeanReference(type = ResourceBlockPersistence.class)
1907            protected ResourceBlockPersistence resourceBlockPersistence;
1908            @BeanReference(type = ResourceBlockPermissionPersistence.class)
1909            protected ResourceBlockPermissionPersistence resourceBlockPermissionPersistence;
1910            @BeanReference(type = ResourceCodePersistence.class)
1911            protected ResourceCodePersistence resourceCodePersistence;
1912            @BeanReference(type = ResourcePermissionPersistence.class)
1913            protected ResourcePermissionPersistence resourcePermissionPersistence;
1914            @BeanReference(type = ResourceTypePermissionPersistence.class)
1915            protected ResourceTypePermissionPersistence resourceTypePermissionPersistence;
1916            @BeanReference(type = RolePersistence.class)
1917            protected RolePersistence rolePersistence;
1918            @BeanReference(type = ServiceComponentPersistence.class)
1919            protected ServiceComponentPersistence serviceComponentPersistence;
1920            @BeanReference(type = ShardPersistence.class)
1921            protected ShardPersistence shardPersistence;
1922            @BeanReference(type = SubscriptionPersistence.class)
1923            protected SubscriptionPersistence subscriptionPersistence;
1924            @BeanReference(type = TeamPersistence.class)
1925            protected TeamPersistence teamPersistence;
1926            @BeanReference(type = TicketPersistence.class)
1927            protected TicketPersistence ticketPersistence;
1928            @BeanReference(type = UserPersistence.class)
1929            protected UserPersistence userPersistence;
1930            @BeanReference(type = UserGroupPersistence.class)
1931            protected UserGroupPersistence userGroupPersistence;
1932            @BeanReference(type = UserGroupGroupRolePersistence.class)
1933            protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1934            @BeanReference(type = UserGroupRolePersistence.class)
1935            protected UserGroupRolePersistence userGroupRolePersistence;
1936            @BeanReference(type = UserIdMapperPersistence.class)
1937            protected UserIdMapperPersistence userIdMapperPersistence;
1938            @BeanReference(type = UserNotificationEventPersistence.class)
1939            protected UserNotificationEventPersistence userNotificationEventPersistence;
1940            @BeanReference(type = UserTrackerPersistence.class)
1941            protected UserTrackerPersistence userTrackerPersistence;
1942            @BeanReference(type = UserTrackerPathPersistence.class)
1943            protected UserTrackerPathPersistence userTrackerPathPersistence;
1944            @BeanReference(type = VirtualHostPersistence.class)
1945            protected VirtualHostPersistence virtualHostPersistence;
1946            @BeanReference(type = WebDAVPropsPersistence.class)
1947            protected WebDAVPropsPersistence webDAVPropsPersistence;
1948            @BeanReference(type = WebsitePersistence.class)
1949            protected WebsitePersistence websitePersistence;
1950            @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
1951            protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
1952            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
1953            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
1954            private static final String _SQL_SELECT_LAYOUTSET = "SELECT layoutSet FROM LayoutSet layoutSet";
1955            private static final String _SQL_SELECT_LAYOUTSET_WHERE = "SELECT layoutSet FROM LayoutSet layoutSet WHERE ";
1956            private static final String _SQL_COUNT_LAYOUTSET = "SELECT COUNT(layoutSet) FROM LayoutSet layoutSet";
1957            private static final String _SQL_COUNT_LAYOUTSET_WHERE = "SELECT COUNT(layoutSet) FROM LayoutSet layoutSet WHERE ";
1958            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "layoutSet.groupId = ?";
1959            private static final String _FINDER_COLUMN_LAYOUTSETPROTOTYPEUUID_LAYOUTSETPROTOTYPEUUID_1 =
1960                    "layoutSet.layoutSetPrototypeUuid IS NULL";
1961            private static final String _FINDER_COLUMN_LAYOUTSETPROTOTYPEUUID_LAYOUTSETPROTOTYPEUUID_2 =
1962                    "layoutSet.layoutSetPrototypeUuid = ?";
1963            private static final String _FINDER_COLUMN_LAYOUTSETPROTOTYPEUUID_LAYOUTSETPROTOTYPEUUID_3 =
1964                    "(layoutSet.layoutSetPrototypeUuid IS NULL OR layoutSet.layoutSetPrototypeUuid = ?)";
1965            private static final String _FINDER_COLUMN_G_P_GROUPID_2 = "layoutSet.groupId = ? AND ";
1966            private static final String _FINDER_COLUMN_G_P_PRIVATELAYOUT_2 = "layoutSet.privateLayout = ?";
1967            private static final String _ORDER_BY_ENTITY_ALIAS = "layoutSet.";
1968            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No LayoutSet exists with the primary key ";
1969            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No LayoutSet exists with the key {";
1970            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1971            private static Log _log = LogFactoryUtil.getLog(LayoutSetPersistenceImpl.class);
1972            private static LayoutSet _nullLayoutSet = new LayoutSetImpl() {
1973                            @Override
1974                            public Object clone() {
1975                                    return this;
1976                            }
1977    
1978                            @Override
1979                            public CacheModel<LayoutSet> toCacheModel() {
1980                                    return _nullLayoutSetCacheModel;
1981                            }
1982                    };
1983    
1984            private static CacheModel<LayoutSet> _nullLayoutSetCacheModel = new CacheModel<LayoutSet>() {
1985                            public LayoutSet toEntityModel() {
1986                                    return _nullLayoutSet;
1987                            }
1988                    };
1989    }