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