001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.service.persistence;
016    
017    import com.liferay.portal.NoSuchLayoutSetException;
018    import com.liferay.portal.NoSuchModelException;
019    import com.liferay.portal.kernel.annotation.BeanReference;
020    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
021    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
023    import com.liferay.portal.kernel.dao.orm.FinderPath;
024    import com.liferay.portal.kernel.dao.orm.Query;
025    import com.liferay.portal.kernel.dao.orm.QueryPos;
026    import com.liferay.portal.kernel.dao.orm.QueryUtil;
027    import com.liferay.portal.kernel.dao.orm.Session;
028    import com.liferay.portal.kernel.exception.SystemException;
029    import com.liferay.portal.kernel.log.Log;
030    import com.liferay.portal.kernel.log.LogFactoryUtil;
031    import com.liferay.portal.kernel.util.GetterUtil;
032    import com.liferay.portal.kernel.util.InstanceFactory;
033    import com.liferay.portal.kernel.util.OrderByComparator;
034    import com.liferay.portal.kernel.util.StringBundler;
035    import com.liferay.portal.kernel.util.StringPool;
036    import com.liferay.portal.kernel.util.StringUtil;
037    import com.liferay.portal.kernel.util.Validator;
038    import com.liferay.portal.model.LayoutSet;
039    import com.liferay.portal.model.ModelListener;
040    import com.liferay.portal.model.impl.LayoutSetImpl;
041    import com.liferay.portal.model.impl.LayoutSetModelImpl;
042    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
043    
044    import java.io.Serializable;
045    
046    import java.util.ArrayList;
047    import java.util.Collections;
048    import java.util.List;
049    
050    /**
051     * The persistence for the layout set service.
052     *
053     * <p>
054     * Never modify this class directly. Modify <code>service.xml</code> and rerun ServiceBuilder to regnerate this class.
055     * </p>
056     *
057     * <p>
058     * Caching information and settings can be found in <code>portal.properties</code>
059     * </p>
060     *
061     * @author Brian Wing Shun Chan
062     * @see LayoutSetPersistence
063     * @see LayoutSetUtil
064     * @generated
065     */
066    public class LayoutSetPersistenceImpl extends BasePersistenceImpl<LayoutSet>
067            implements LayoutSetPersistence {
068            public static final String FINDER_CLASS_NAME_ENTITY = LayoutSetImpl.class.getName();
069            public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
070                    ".List";
071            public static final FinderPath FINDER_PATH_FIND_BY_GROUPID = new FinderPath(LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
072                            LayoutSetModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
073                            "findByGroupId",
074                            new String[] {
075                                    Long.class.getName(),
076                                    
077                            "java.lang.Integer", "java.lang.Integer",
078                                    "com.liferay.portal.kernel.util.OrderByComparator"
079                            });
080            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
081                            LayoutSetModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
082                            "countByGroupId", new String[] { Long.class.getName() });
083            public static final FinderPath FINDER_PATH_FETCH_BY_VIRTUALHOST = new FinderPath(LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
084                            LayoutSetModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
085                            "fetchByVirtualHost", new String[] { String.class.getName() });
086            public static final FinderPath FINDER_PATH_COUNT_BY_VIRTUALHOST = new FinderPath(LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
087                            LayoutSetModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
088                            "countByVirtualHost", new String[] { String.class.getName() });
089            public static final FinderPath FINDER_PATH_FETCH_BY_G_P = new FinderPath(LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
090                            LayoutSetModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
091                            "fetchByG_P",
092                            new String[] { Long.class.getName(), Boolean.class.getName() });
093            public static final FinderPath FINDER_PATH_COUNT_BY_G_P = new FinderPath(LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
094                            LayoutSetModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
095                            "countByG_P",
096                            new String[] { Long.class.getName(), Boolean.class.getName() });
097            public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
098                            LayoutSetModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
099                            "findAll", new String[0]);
100            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
101                            LayoutSetModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
102                            "countAll", new String[0]);
103    
104            /**
105             * Caches the layout set in the entity cache if it is enabled.
106             *
107             * @param layoutSet the layout set to cache
108             */
109            public void cacheResult(LayoutSet layoutSet) {
110                    EntityCacheUtil.putResult(LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
111                            LayoutSetImpl.class, layoutSet.getPrimaryKey(), layoutSet);
112    
113                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_VIRTUALHOST,
114                            new Object[] { layoutSet.getVirtualHost() }, layoutSet);
115    
116                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P,
117                            new Object[] {
118                                    new Long(layoutSet.getGroupId()),
119                                    Boolean.valueOf(layoutSet.getPrivateLayout())
120                            }, layoutSet);
121            }
122    
123            /**
124             * Caches the layout sets in the entity cache if it is enabled.
125             *
126             * @param layoutSets the layout sets to cache
127             */
128            public void cacheResult(List<LayoutSet> layoutSets) {
129                    for (LayoutSet layoutSet : layoutSets) {
130                            if (EntityCacheUtil.getResult(
131                                                    LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
132                                                    LayoutSetImpl.class, layoutSet.getPrimaryKey(), this) == null) {
133                                    cacheResult(layoutSet);
134                            }
135                    }
136            }
137    
138            /**
139             * Clears the cache for all layout sets.
140             *
141             * <p>
142             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
143             * </p>
144             */
145            public void clearCache() {
146                    CacheRegistryUtil.clear(LayoutSetImpl.class.getName());
147                    EntityCacheUtil.clearCache(LayoutSetImpl.class.getName());
148                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
149                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
150            }
151    
152            /**
153             * Clears the cache for the layout set.
154             *
155             * <p>
156             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
157             * </p>
158             */
159            public void clearCache(LayoutSet layoutSet) {
160                    EntityCacheUtil.removeResult(LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
161                            LayoutSetImpl.class, layoutSet.getPrimaryKey());
162    
163                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_VIRTUALHOST,
164                            new Object[] { layoutSet.getVirtualHost() });
165    
166                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P,
167                            new Object[] {
168                                    new Long(layoutSet.getGroupId()),
169                                    Boolean.valueOf(layoutSet.getPrivateLayout())
170                            });
171            }
172    
173            /**
174             * Creates a new layout set with the primary key.
175             *
176             * @param layoutSetId the primary key for the new layout set
177             * @return the new layout set
178             */
179            public LayoutSet create(long layoutSetId) {
180                    LayoutSet layoutSet = new LayoutSetImpl();
181    
182                    layoutSet.setNew(true);
183                    layoutSet.setPrimaryKey(layoutSetId);
184    
185                    return layoutSet;
186            }
187    
188            /**
189             * Removes the layout set with the primary key from the database. Also notifies the appropriate model listeners.
190             *
191             * @param primaryKey the primary key of the layout set to remove
192             * @return the layout set that was removed
193             * @throws com.liferay.portal.NoSuchModelException if a layout set with the primary key could not be found
194             * @throws SystemException if a system exception occurred
195             */
196            public LayoutSet remove(Serializable primaryKey)
197                    throws NoSuchModelException, SystemException {
198                    return remove(((Long)primaryKey).longValue());
199            }
200    
201            /**
202             * Removes the layout set with the primary key from the database. Also notifies the appropriate model listeners.
203             *
204             * @param layoutSetId the primary key of the layout set to remove
205             * @return the layout set that was removed
206             * @throws com.liferay.portal.NoSuchLayoutSetException if a layout set with the primary key could not be found
207             * @throws SystemException if a system exception occurred
208             */
209            public LayoutSet remove(long layoutSetId)
210                    throws NoSuchLayoutSetException, SystemException {
211                    Session session = null;
212    
213                    try {
214                            session = openSession();
215    
216                            LayoutSet layoutSet = (LayoutSet)session.get(LayoutSetImpl.class,
217                                            new Long(layoutSetId));
218    
219                            if (layoutSet == null) {
220                                    if (_log.isWarnEnabled()) {
221                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + layoutSetId);
222                                    }
223    
224                                    throw new NoSuchLayoutSetException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
225                                            layoutSetId);
226                            }
227    
228                            return remove(layoutSet);
229                    }
230                    catch (NoSuchLayoutSetException nsee) {
231                            throw nsee;
232                    }
233                    catch (Exception e) {
234                            throw processException(e);
235                    }
236                    finally {
237                            closeSession(session);
238                    }
239            }
240    
241            protected LayoutSet removeImpl(LayoutSet layoutSet)
242                    throws SystemException {
243                    layoutSet = toUnwrappedModel(layoutSet);
244    
245                    Session session = null;
246    
247                    try {
248                            session = openSession();
249    
250                            if (layoutSet.isCachedModel() || BatchSessionUtil.isEnabled()) {
251                                    Object staleObject = session.get(LayoutSetImpl.class,
252                                                    layoutSet.getPrimaryKeyObj());
253    
254                                    if (staleObject != null) {
255                                            session.evict(staleObject);
256                                    }
257                            }
258    
259                            session.delete(layoutSet);
260    
261                            session.flush();
262                    }
263                    catch (Exception e) {
264                            throw processException(e);
265                    }
266                    finally {
267                            closeSession(session);
268                    }
269    
270                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
271    
272                    LayoutSetModelImpl layoutSetModelImpl = (LayoutSetModelImpl)layoutSet;
273    
274                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_VIRTUALHOST,
275                            new Object[] { layoutSetModelImpl.getOriginalVirtualHost() });
276    
277                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P,
278                            new Object[] {
279                                    new Long(layoutSetModelImpl.getOriginalGroupId()),
280                                    Boolean.valueOf(layoutSetModelImpl.getOriginalPrivateLayout())
281                            });
282    
283                    EntityCacheUtil.removeResult(LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
284                            LayoutSetImpl.class, layoutSet.getPrimaryKey());
285    
286                    return layoutSet;
287            }
288    
289            public LayoutSet updateImpl(com.liferay.portal.model.LayoutSet layoutSet,
290                    boolean merge) throws SystemException {
291                    layoutSet = toUnwrappedModel(layoutSet);
292    
293                    boolean isNew = layoutSet.isNew();
294    
295                    LayoutSetModelImpl layoutSetModelImpl = (LayoutSetModelImpl)layoutSet;
296    
297                    Session session = null;
298    
299                    try {
300                            session = openSession();
301    
302                            BatchSessionUtil.update(session, layoutSet, merge);
303    
304                            layoutSet.setNew(false);
305                    }
306                    catch (Exception e) {
307                            throw processException(e);
308                    }
309                    finally {
310                            closeSession(session);
311                    }
312    
313                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
314    
315                    EntityCacheUtil.putResult(LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
316                            LayoutSetImpl.class, layoutSet.getPrimaryKey(), layoutSet);
317    
318                    if (!isNew &&
319                                    (!Validator.equals(layoutSet.getVirtualHost(),
320                                            layoutSetModelImpl.getOriginalVirtualHost()))) {
321                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_VIRTUALHOST,
322                                    new Object[] { layoutSetModelImpl.getOriginalVirtualHost() });
323                    }
324    
325                    if (isNew ||
326                                    (!Validator.equals(layoutSet.getVirtualHost(),
327                                            layoutSetModelImpl.getOriginalVirtualHost()))) {
328                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_VIRTUALHOST,
329                                    new Object[] { layoutSet.getVirtualHost() }, layoutSet);
330                    }
331    
332                    if (!isNew &&
333                                    ((layoutSet.getGroupId() != layoutSetModelImpl.getOriginalGroupId()) ||
334                                    (layoutSet.getPrivateLayout() != layoutSetModelImpl.getOriginalPrivateLayout()))) {
335                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P,
336                                    new Object[] {
337                                            new Long(layoutSetModelImpl.getOriginalGroupId()),
338                                            Boolean.valueOf(
339                                                    layoutSetModelImpl.getOriginalPrivateLayout())
340                                    });
341                    }
342    
343                    if (isNew ||
344                                    ((layoutSet.getGroupId() != layoutSetModelImpl.getOriginalGroupId()) ||
345                                    (layoutSet.getPrivateLayout() != layoutSetModelImpl.getOriginalPrivateLayout()))) {
346                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P,
347                                    new Object[] {
348                                            new Long(layoutSet.getGroupId()),
349                                            Boolean.valueOf(layoutSet.getPrivateLayout())
350                                    }, layoutSet);
351                    }
352    
353                    return layoutSet;
354            }
355    
356            protected LayoutSet toUnwrappedModel(LayoutSet layoutSet) {
357                    if (layoutSet instanceof LayoutSetImpl) {
358                            return layoutSet;
359                    }
360    
361                    LayoutSetImpl layoutSetImpl = new LayoutSetImpl();
362    
363                    layoutSetImpl.setNew(layoutSet.isNew());
364                    layoutSetImpl.setPrimaryKey(layoutSet.getPrimaryKey());
365    
366                    layoutSetImpl.setLayoutSetId(layoutSet.getLayoutSetId());
367                    layoutSetImpl.setGroupId(layoutSet.getGroupId());
368                    layoutSetImpl.setCompanyId(layoutSet.getCompanyId());
369                    layoutSetImpl.setPrivateLayout(layoutSet.isPrivateLayout());
370                    layoutSetImpl.setLogo(layoutSet.isLogo());
371                    layoutSetImpl.setLogoId(layoutSet.getLogoId());
372                    layoutSetImpl.setThemeId(layoutSet.getThemeId());
373                    layoutSetImpl.setColorSchemeId(layoutSet.getColorSchemeId());
374                    layoutSetImpl.setWapThemeId(layoutSet.getWapThemeId());
375                    layoutSetImpl.setWapColorSchemeId(layoutSet.getWapColorSchemeId());
376                    layoutSetImpl.setCss(layoutSet.getCss());
377                    layoutSetImpl.setPageCount(layoutSet.getPageCount());
378                    layoutSetImpl.setVirtualHost(layoutSet.getVirtualHost());
379                    layoutSetImpl.setSettings(layoutSet.getSettings());
380                    layoutSetImpl.setLayoutSetPrototypeId(layoutSet.getLayoutSetPrototypeId());
381    
382                    return layoutSetImpl;
383            }
384    
385            /**
386             * Finds the layout set with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
387             *
388             * @param primaryKey the primary key of the layout set to find
389             * @return the layout set
390             * @throws com.liferay.portal.NoSuchModelException if a layout set with the primary key could not be found
391             * @throws SystemException if a system exception occurred
392             */
393            public LayoutSet findByPrimaryKey(Serializable primaryKey)
394                    throws NoSuchModelException, SystemException {
395                    return findByPrimaryKey(((Long)primaryKey).longValue());
396            }
397    
398            /**
399             * Finds the layout set with the primary key or throws a {@link com.liferay.portal.NoSuchLayoutSetException} if it could not be found.
400             *
401             * @param layoutSetId the primary key of the layout set to find
402             * @return the layout set
403             * @throws com.liferay.portal.NoSuchLayoutSetException if a layout set with the primary key could not be found
404             * @throws SystemException if a system exception occurred
405             */
406            public LayoutSet findByPrimaryKey(long layoutSetId)
407                    throws NoSuchLayoutSetException, SystemException {
408                    LayoutSet layoutSet = fetchByPrimaryKey(layoutSetId);
409    
410                    if (layoutSet == null) {
411                            if (_log.isWarnEnabled()) {
412                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + layoutSetId);
413                            }
414    
415                            throw new NoSuchLayoutSetException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
416                                    layoutSetId);
417                    }
418    
419                    return layoutSet;
420            }
421    
422            /**
423             * Finds the layout set with the primary key or returns <code>null</code> if it could not be found.
424             *
425             * @param primaryKey the primary key of the layout set to find
426             * @return the layout set, or <code>null</code> if a layout set with the primary key could not be found
427             * @throws SystemException if a system exception occurred
428             */
429            public LayoutSet fetchByPrimaryKey(Serializable primaryKey)
430                    throws SystemException {
431                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
432            }
433    
434            /**
435             * Finds the layout set with the primary key or returns <code>null</code> if it could not be found.
436             *
437             * @param layoutSetId the primary key of the layout set to find
438             * @return the layout set, or <code>null</code> if a layout set with the primary key could not be found
439             * @throws SystemException if a system exception occurred
440             */
441            public LayoutSet fetchByPrimaryKey(long layoutSetId)
442                    throws SystemException {
443                    LayoutSet layoutSet = (LayoutSet)EntityCacheUtil.getResult(LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
444                                    LayoutSetImpl.class, layoutSetId, this);
445    
446                    if (layoutSet == null) {
447                            Session session = null;
448    
449                            try {
450                                    session = openSession();
451    
452                                    layoutSet = (LayoutSet)session.get(LayoutSetImpl.class,
453                                                    new Long(layoutSetId));
454                            }
455                            catch (Exception e) {
456                                    throw processException(e);
457                            }
458                            finally {
459                                    if (layoutSet != null) {
460                                            cacheResult(layoutSet);
461                                    }
462    
463                                    closeSession(session);
464                            }
465                    }
466    
467                    return layoutSet;
468            }
469    
470            /**
471             * Finds all the layout sets where groupId = &#63;.
472             *
473             * @param groupId the group id to search with
474             * @return the matching layout sets
475             * @throws SystemException if a system exception occurred
476             */
477            public List<LayoutSet> findByGroupId(long groupId)
478                    throws SystemException {
479                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
480            }
481    
482            /**
483             * Finds a range of all the layout sets where groupId = &#63;.
484             *
485             * <p>
486             * 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.
487             * </p>
488             *
489             * @param groupId the group id to search with
490             * @param start the lower bound of the range of layout sets to return
491             * @param end the upper bound of the range of layout sets to return (not inclusive)
492             * @return the range of matching layout sets
493             * @throws SystemException if a system exception occurred
494             */
495            public List<LayoutSet> findByGroupId(long groupId, int start, int end)
496                    throws SystemException {
497                    return findByGroupId(groupId, start, end, null);
498            }
499    
500            /**
501             * Finds an ordered range of all the layout sets where groupId = &#63;.
502             *
503             * <p>
504             * 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.
505             * </p>
506             *
507             * @param groupId the group id to search with
508             * @param start the lower bound of the range of layout sets to return
509             * @param end the upper bound of the range of layout sets to return (not inclusive)
510             * @param orderByComparator the comparator to order the results by
511             * @return the ordered range of matching layout sets
512             * @throws SystemException if a system exception occurred
513             */
514            public List<LayoutSet> findByGroupId(long groupId, int start, int end,
515                    OrderByComparator orderByComparator) throws SystemException {
516                    Object[] finderArgs = new Object[] {
517                                    groupId,
518                                    
519                                    String.valueOf(start), String.valueOf(end),
520                                    String.valueOf(orderByComparator)
521                            };
522    
523                    List<LayoutSet> list = (List<LayoutSet>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
524                                    finderArgs, this);
525    
526                    if (list == null) {
527                            Session session = null;
528    
529                            try {
530                                    session = openSession();
531    
532                                    StringBundler query = null;
533    
534                                    if (orderByComparator != null) {
535                                            query = new StringBundler(3 +
536                                                            (orderByComparator.getOrderByFields().length * 3));
537                                    }
538                                    else {
539                                            query = new StringBundler(2);
540                                    }
541    
542                                    query.append(_SQL_SELECT_LAYOUTSET_WHERE);
543    
544                                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
545    
546                                    if (orderByComparator != null) {
547                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
548                                                    orderByComparator);
549                                    }
550    
551                                    String sql = query.toString();
552    
553                                    Query q = session.createQuery(sql);
554    
555                                    QueryPos qPos = QueryPos.getInstance(q);
556    
557                                    qPos.add(groupId);
558    
559                                    list = (List<LayoutSet>)QueryUtil.list(q, getDialect(), start,
560                                                    end);
561                            }
562                            catch (Exception e) {
563                                    throw processException(e);
564                            }
565                            finally {
566                                    if (list == null) {
567                                            list = new ArrayList<LayoutSet>();
568                                    }
569    
570                                    cacheResult(list);
571    
572                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
573                                            finderArgs, list);
574    
575                                    closeSession(session);
576                            }
577                    }
578    
579                    return list;
580            }
581    
582            /**
583             * Finds the first layout set in the ordered set where groupId = &#63;.
584             *
585             * <p>
586             * 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.
587             * </p>
588             *
589             * @param groupId the group id to search with
590             * @param orderByComparator the comparator to order the set by
591             * @return the first matching layout set
592             * @throws com.liferay.portal.NoSuchLayoutSetException if a matching layout set could not be found
593             * @throws SystemException if a system exception occurred
594             */
595            public LayoutSet findByGroupId_First(long groupId,
596                    OrderByComparator orderByComparator)
597                    throws NoSuchLayoutSetException, SystemException {
598                    List<LayoutSet> list = findByGroupId(groupId, 0, 1, orderByComparator);
599    
600                    if (list.isEmpty()) {
601                            StringBundler msg = new StringBundler(4);
602    
603                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
604    
605                            msg.append("groupId=");
606                            msg.append(groupId);
607    
608                            msg.append(StringPool.CLOSE_CURLY_BRACE);
609    
610                            throw new NoSuchLayoutSetException(msg.toString());
611                    }
612                    else {
613                            return list.get(0);
614                    }
615            }
616    
617            /**
618             * Finds the last layout set in the ordered set where groupId = &#63;.
619             *
620             * <p>
621             * 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.
622             * </p>
623             *
624             * @param groupId the group id to search with
625             * @param orderByComparator the comparator to order the set by
626             * @return the last matching layout set
627             * @throws com.liferay.portal.NoSuchLayoutSetException if a matching layout set could not be found
628             * @throws SystemException if a system exception occurred
629             */
630            public LayoutSet findByGroupId_Last(long groupId,
631                    OrderByComparator orderByComparator)
632                    throws NoSuchLayoutSetException, SystemException {
633                    int count = countByGroupId(groupId);
634    
635                    List<LayoutSet> list = findByGroupId(groupId, count - 1, count,
636                                    orderByComparator);
637    
638                    if (list.isEmpty()) {
639                            StringBundler msg = new StringBundler(4);
640    
641                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
642    
643                            msg.append("groupId=");
644                            msg.append(groupId);
645    
646                            msg.append(StringPool.CLOSE_CURLY_BRACE);
647    
648                            throw new NoSuchLayoutSetException(msg.toString());
649                    }
650                    else {
651                            return list.get(0);
652                    }
653            }
654    
655            /**
656             * Finds the layout sets before and after the current layout set in the ordered set where groupId = &#63;.
657             *
658             * <p>
659             * 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.
660             * </p>
661             *
662             * @param layoutSetId the primary key of the current layout set
663             * @param groupId the group id to search with
664             * @param orderByComparator the comparator to order the set by
665             * @return the previous, current, and next layout set
666             * @throws com.liferay.portal.NoSuchLayoutSetException if a layout set with the primary key could not be found
667             * @throws SystemException if a system exception occurred
668             */
669            public LayoutSet[] findByGroupId_PrevAndNext(long layoutSetId,
670                    long groupId, OrderByComparator orderByComparator)
671                    throws NoSuchLayoutSetException, SystemException {
672                    LayoutSet layoutSet = findByPrimaryKey(layoutSetId);
673    
674                    Session session = null;
675    
676                    try {
677                            session = openSession();
678    
679                            LayoutSet[] array = new LayoutSetImpl[3];
680    
681                            array[0] = getByGroupId_PrevAndNext(session, layoutSet, groupId,
682                                            orderByComparator, true);
683    
684                            array[1] = layoutSet;
685    
686                            array[2] = getByGroupId_PrevAndNext(session, layoutSet, groupId,
687                                            orderByComparator, false);
688    
689                            return array;
690                    }
691                    catch (Exception e) {
692                            throw processException(e);
693                    }
694                    finally {
695                            closeSession(session);
696                    }
697            }
698    
699            protected LayoutSet getByGroupId_PrevAndNext(Session session,
700                    LayoutSet layoutSet, long groupId, OrderByComparator orderByComparator,
701                    boolean previous) {
702                    StringBundler query = null;
703    
704                    if (orderByComparator != null) {
705                            query = new StringBundler(6 +
706                                            (orderByComparator.getOrderByFields().length * 6));
707                    }
708                    else {
709                            query = new StringBundler(3);
710                    }
711    
712                    query.append(_SQL_SELECT_LAYOUTSET_WHERE);
713    
714                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
715    
716                    if (orderByComparator != null) {
717                            String[] orderByFields = orderByComparator.getOrderByFields();
718    
719                            if (orderByFields.length > 0) {
720                                    query.append(WHERE_AND);
721                            }
722    
723                            for (int i = 0; i < orderByFields.length; i++) {
724                                    query.append(_ORDER_BY_ENTITY_ALIAS);
725                                    query.append(orderByFields[i]);
726    
727                                    if ((i + 1) < orderByFields.length) {
728                                            if (orderByComparator.isAscending() ^ previous) {
729                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
730                                            }
731                                            else {
732                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
733                                            }
734                                    }
735                                    else {
736                                            if (orderByComparator.isAscending() ^ previous) {
737                                                    query.append(WHERE_GREATER_THAN);
738                                            }
739                                            else {
740                                                    query.append(WHERE_LESSER_THAN);
741                                            }
742                                    }
743                            }
744    
745                            query.append(ORDER_BY_CLAUSE);
746    
747                            for (int i = 0; i < orderByFields.length; i++) {
748                                    query.append(_ORDER_BY_ENTITY_ALIAS);
749                                    query.append(orderByFields[i]);
750    
751                                    if ((i + 1) < orderByFields.length) {
752                                            if (orderByComparator.isAscending() ^ previous) {
753                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
754                                            }
755                                            else {
756                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
757                                            }
758                                    }
759                                    else {
760                                            if (orderByComparator.isAscending() ^ previous) {
761                                                    query.append(ORDER_BY_ASC);
762                                            }
763                                            else {
764                                                    query.append(ORDER_BY_DESC);
765                                            }
766                                    }
767                            }
768                    }
769    
770                    String sql = query.toString();
771    
772                    Query q = session.createQuery(sql);
773    
774                    q.setFirstResult(0);
775                    q.setMaxResults(2);
776    
777                    QueryPos qPos = QueryPos.getInstance(q);
778    
779                    qPos.add(groupId);
780    
781                    if (orderByComparator != null) {
782                            Object[] values = orderByComparator.getOrderByValues(layoutSet);
783    
784                            for (Object value : values) {
785                                    qPos.add(value);
786                            }
787                    }
788    
789                    List<LayoutSet> list = q.list();
790    
791                    if (list.size() == 2) {
792                            return list.get(1);
793                    }
794                    else {
795                            return null;
796                    }
797            }
798    
799            /**
800             * Finds the layout set where virtualHost = &#63; or throws a {@link com.liferay.portal.NoSuchLayoutSetException} if it could not be found.
801             *
802             * @param virtualHost the virtual host to search with
803             * @return the matching layout set
804             * @throws com.liferay.portal.NoSuchLayoutSetException if a matching layout set could not be found
805             * @throws SystemException if a system exception occurred
806             */
807            public LayoutSet findByVirtualHost(String virtualHost)
808                    throws NoSuchLayoutSetException, SystemException {
809                    LayoutSet layoutSet = fetchByVirtualHost(virtualHost);
810    
811                    if (layoutSet == null) {
812                            StringBundler msg = new StringBundler(4);
813    
814                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
815    
816                            msg.append("virtualHost=");
817                            msg.append(virtualHost);
818    
819                            msg.append(StringPool.CLOSE_CURLY_BRACE);
820    
821                            if (_log.isWarnEnabled()) {
822                                    _log.warn(msg.toString());
823                            }
824    
825                            throw new NoSuchLayoutSetException(msg.toString());
826                    }
827    
828                    return layoutSet;
829            }
830    
831            /**
832             * Finds the layout set where virtualHost = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
833             *
834             * @param virtualHost the virtual host to search with
835             * @return the matching layout set, or <code>null</code> if a matching layout set could not be found
836             * @throws SystemException if a system exception occurred
837             */
838            public LayoutSet fetchByVirtualHost(String virtualHost)
839                    throws SystemException {
840                    return fetchByVirtualHost(virtualHost, true);
841            }
842    
843            /**
844             * Finds the layout set where virtualHost = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
845             *
846             * @param virtualHost the virtual host to search with
847             * @return the matching layout set, or <code>null</code> if a matching layout set could not be found
848             * @throws SystemException if a system exception occurred
849             */
850            public LayoutSet fetchByVirtualHost(String virtualHost,
851                    boolean retrieveFromCache) throws SystemException {
852                    Object[] finderArgs = new Object[] { virtualHost };
853    
854                    Object result = null;
855    
856                    if (retrieveFromCache) {
857                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_VIRTUALHOST,
858                                            finderArgs, this);
859                    }
860    
861                    if (result == null) {
862                            Session session = null;
863    
864                            try {
865                                    session = openSession();
866    
867                                    StringBundler query = new StringBundler(2);
868    
869                                    query.append(_SQL_SELECT_LAYOUTSET_WHERE);
870    
871                                    if (virtualHost == null) {
872                                            query.append(_FINDER_COLUMN_VIRTUALHOST_VIRTUALHOST_1);
873                                    }
874                                    else {
875                                            if (virtualHost.equals(StringPool.BLANK)) {
876                                                    query.append(_FINDER_COLUMN_VIRTUALHOST_VIRTUALHOST_3);
877                                            }
878                                            else {
879                                                    query.append(_FINDER_COLUMN_VIRTUALHOST_VIRTUALHOST_2);
880                                            }
881                                    }
882    
883                                    String sql = query.toString();
884    
885                                    Query q = session.createQuery(sql);
886    
887                                    QueryPos qPos = QueryPos.getInstance(q);
888    
889                                    if (virtualHost != null) {
890                                            qPos.add(virtualHost);
891                                    }
892    
893                                    List<LayoutSet> list = q.list();
894    
895                                    result = list;
896    
897                                    LayoutSet layoutSet = null;
898    
899                                    if (list.isEmpty()) {
900                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_VIRTUALHOST,
901                                                    finderArgs, list);
902                                    }
903                                    else {
904                                            layoutSet = list.get(0);
905    
906                                            cacheResult(layoutSet);
907    
908                                            if ((layoutSet.getVirtualHost() == null) ||
909                                                            !layoutSet.getVirtualHost().equals(virtualHost)) {
910                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_VIRTUALHOST,
911                                                            finderArgs, layoutSet);
912                                            }
913                                    }
914    
915                                    return layoutSet;
916                            }
917                            catch (Exception e) {
918                                    throw processException(e);
919                            }
920                            finally {
921                                    if (result == null) {
922                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_VIRTUALHOST,
923                                                    finderArgs, new ArrayList<LayoutSet>());
924                                    }
925    
926                                    closeSession(session);
927                            }
928                    }
929                    else {
930                            if (result instanceof List<?>) {
931                                    return null;
932                            }
933                            else {
934                                    return (LayoutSet)result;
935                            }
936                    }
937            }
938    
939            /**
940             * Finds the layout set where groupId = &#63; and privateLayout = &#63; or throws a {@link com.liferay.portal.NoSuchLayoutSetException} if it could not be found.
941             *
942             * @param groupId the group id to search with
943             * @param privateLayout the private layout to search with
944             * @return the matching layout set
945             * @throws com.liferay.portal.NoSuchLayoutSetException if a matching layout set could not be found
946             * @throws SystemException if a system exception occurred
947             */
948            public LayoutSet findByG_P(long groupId, boolean privateLayout)
949                    throws NoSuchLayoutSetException, SystemException {
950                    LayoutSet layoutSet = fetchByG_P(groupId, privateLayout);
951    
952                    if (layoutSet == null) {
953                            StringBundler msg = new StringBundler(6);
954    
955                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
956    
957                            msg.append("groupId=");
958                            msg.append(groupId);
959    
960                            msg.append(", privateLayout=");
961                            msg.append(privateLayout);
962    
963                            msg.append(StringPool.CLOSE_CURLY_BRACE);
964    
965                            if (_log.isWarnEnabled()) {
966                                    _log.warn(msg.toString());
967                            }
968    
969                            throw new NoSuchLayoutSetException(msg.toString());
970                    }
971    
972                    return layoutSet;
973            }
974    
975            /**
976             * Finds the layout set where groupId = &#63; and privateLayout = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
977             *
978             * @param groupId the group id to search with
979             * @param privateLayout the private layout to search with
980             * @return the matching layout set, or <code>null</code> if a matching layout set could not be found
981             * @throws SystemException if a system exception occurred
982             */
983            public LayoutSet fetchByG_P(long groupId, boolean privateLayout)
984                    throws SystemException {
985                    return fetchByG_P(groupId, privateLayout, true);
986            }
987    
988            /**
989             * Finds 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.
990             *
991             * @param groupId the group id to search with
992             * @param privateLayout the private layout to search with
993             * @return the matching layout set, or <code>null</code> if a matching layout set could not be found
994             * @throws SystemException if a system exception occurred
995             */
996            public LayoutSet fetchByG_P(long groupId, boolean privateLayout,
997                    boolean retrieveFromCache) throws SystemException {
998                    Object[] finderArgs = new Object[] { groupId, privateLayout };
999    
1000                    Object result = null;
1001    
1002                    if (retrieveFromCache) {
1003                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_P,
1004                                            finderArgs, this);
1005                    }
1006    
1007                    if (result == null) {
1008                            Session session = null;
1009    
1010                            try {
1011                                    session = openSession();
1012    
1013                                    StringBundler query = new StringBundler(3);
1014    
1015                                    query.append(_SQL_SELECT_LAYOUTSET_WHERE);
1016    
1017                                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
1018    
1019                                    query.append(_FINDER_COLUMN_G_P_PRIVATELAYOUT_2);
1020    
1021                                    String sql = query.toString();
1022    
1023                                    Query q = session.createQuery(sql);
1024    
1025                                    QueryPos qPos = QueryPos.getInstance(q);
1026    
1027                                    qPos.add(groupId);
1028    
1029                                    qPos.add(privateLayout);
1030    
1031                                    List<LayoutSet> list = q.list();
1032    
1033                                    result = list;
1034    
1035                                    LayoutSet layoutSet = null;
1036    
1037                                    if (list.isEmpty()) {
1038                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P,
1039                                                    finderArgs, list);
1040                                    }
1041                                    else {
1042                                            layoutSet = list.get(0);
1043    
1044                                            cacheResult(layoutSet);
1045    
1046                                            if ((layoutSet.getGroupId() != groupId) ||
1047                                                            (layoutSet.getPrivateLayout() != privateLayout)) {
1048                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P,
1049                                                            finderArgs, layoutSet);
1050                                            }
1051                                    }
1052    
1053                                    return layoutSet;
1054                            }
1055                            catch (Exception e) {
1056                                    throw processException(e);
1057                            }
1058                            finally {
1059                                    if (result == null) {
1060                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P,
1061                                                    finderArgs, new ArrayList<LayoutSet>());
1062                                    }
1063    
1064                                    closeSession(session);
1065                            }
1066                    }
1067                    else {
1068                            if (result instanceof List<?>) {
1069                                    return null;
1070                            }
1071                            else {
1072                                    return (LayoutSet)result;
1073                            }
1074                    }
1075            }
1076    
1077            /**
1078             * Finds all the layout sets.
1079             *
1080             * @return the layout sets
1081             * @throws SystemException if a system exception occurred
1082             */
1083            public List<LayoutSet> findAll() throws SystemException {
1084                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1085            }
1086    
1087            /**
1088             * Finds a range of all the layout sets.
1089             *
1090             * <p>
1091             * 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.
1092             * </p>
1093             *
1094             * @param start the lower bound of the range of layout sets to return
1095             * @param end the upper bound of the range of layout sets to return (not inclusive)
1096             * @return the range of layout sets
1097             * @throws SystemException if a system exception occurred
1098             */
1099            public List<LayoutSet> findAll(int start, int end)
1100                    throws SystemException {
1101                    return findAll(start, end, null);
1102            }
1103    
1104            /**
1105             * Finds an ordered range of all the layout sets.
1106             *
1107             * <p>
1108             * 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.
1109             * </p>
1110             *
1111             * @param start the lower bound of the range of layout sets to return
1112             * @param end the upper bound of the range of layout sets to return (not inclusive)
1113             * @param orderByComparator the comparator to order the results by
1114             * @return the ordered range of layout sets
1115             * @throws SystemException if a system exception occurred
1116             */
1117            public List<LayoutSet> findAll(int start, int end,
1118                    OrderByComparator orderByComparator) throws SystemException {
1119                    Object[] finderArgs = new Object[] {
1120                                    String.valueOf(start), String.valueOf(end),
1121                                    String.valueOf(orderByComparator)
1122                            };
1123    
1124                    List<LayoutSet> list = (List<LayoutSet>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1125                                    finderArgs, this);
1126    
1127                    if (list == null) {
1128                            Session session = null;
1129    
1130                            try {
1131                                    session = openSession();
1132    
1133                                    StringBundler query = null;
1134                                    String sql = null;
1135    
1136                                    if (orderByComparator != null) {
1137                                            query = new StringBundler(2 +
1138                                                            (orderByComparator.getOrderByFields().length * 3));
1139    
1140                                            query.append(_SQL_SELECT_LAYOUTSET);
1141    
1142                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1143                                                    orderByComparator);
1144    
1145                                            sql = query.toString();
1146                                    }
1147                                    else {
1148                                            sql = _SQL_SELECT_LAYOUTSET;
1149                                    }
1150    
1151                                    Query q = session.createQuery(sql);
1152    
1153                                    if (orderByComparator == null) {
1154                                            list = (List<LayoutSet>)QueryUtil.list(q, getDialect(),
1155                                                            start, end, false);
1156    
1157                                            Collections.sort(list);
1158                                    }
1159                                    else {
1160                                            list = (List<LayoutSet>)QueryUtil.list(q, getDialect(),
1161                                                            start, end);
1162                                    }
1163                            }
1164                            catch (Exception e) {
1165                                    throw processException(e);
1166                            }
1167                            finally {
1168                                    if (list == null) {
1169                                            list = new ArrayList<LayoutSet>();
1170                                    }
1171    
1172                                    cacheResult(list);
1173    
1174                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1175    
1176                                    closeSession(session);
1177                            }
1178                    }
1179    
1180                    return list;
1181            }
1182    
1183            /**
1184             * Removes all the layout sets where groupId = &#63; from the database.
1185             *
1186             * @param groupId the group id to search with
1187             * @throws SystemException if a system exception occurred
1188             */
1189            public void removeByGroupId(long groupId) throws SystemException {
1190                    for (LayoutSet layoutSet : findByGroupId(groupId)) {
1191                            remove(layoutSet);
1192                    }
1193            }
1194    
1195            /**
1196             * Removes the layout set where virtualHost = &#63; from the database.
1197             *
1198             * @param virtualHost the virtual host to search with
1199             * @throws SystemException if a system exception occurred
1200             */
1201            public void removeByVirtualHost(String virtualHost)
1202                    throws NoSuchLayoutSetException, SystemException {
1203                    LayoutSet layoutSet = findByVirtualHost(virtualHost);
1204    
1205                    remove(layoutSet);
1206            }
1207    
1208            /**
1209             * Removes the layout set where groupId = &#63; and privateLayout = &#63; from the database.
1210             *
1211             * @param groupId the group id to search with
1212             * @param privateLayout the private layout to search with
1213             * @throws SystemException if a system exception occurred
1214             */
1215            public void removeByG_P(long groupId, boolean privateLayout)
1216                    throws NoSuchLayoutSetException, SystemException {
1217                    LayoutSet layoutSet = findByG_P(groupId, privateLayout);
1218    
1219                    remove(layoutSet);
1220            }
1221    
1222            /**
1223             * Removes all the layout sets from the database.
1224             *
1225             * @throws SystemException if a system exception occurred
1226             */
1227            public void removeAll() throws SystemException {
1228                    for (LayoutSet layoutSet : findAll()) {
1229                            remove(layoutSet);
1230                    }
1231            }
1232    
1233            /**
1234             * Counts all the layout sets where groupId = &#63;.
1235             *
1236             * @param groupId the group id to search with
1237             * @return the number of matching layout sets
1238             * @throws SystemException if a system exception occurred
1239             */
1240            public int countByGroupId(long groupId) throws SystemException {
1241                    Object[] finderArgs = new Object[] { groupId };
1242    
1243                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
1244                                    finderArgs, this);
1245    
1246                    if (count == null) {
1247                            Session session = null;
1248    
1249                            try {
1250                                    session = openSession();
1251    
1252                                    StringBundler query = new StringBundler(2);
1253    
1254                                    query.append(_SQL_COUNT_LAYOUTSET_WHERE);
1255    
1256                                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1257    
1258                                    String sql = query.toString();
1259    
1260                                    Query q = session.createQuery(sql);
1261    
1262                                    QueryPos qPos = QueryPos.getInstance(q);
1263    
1264                                    qPos.add(groupId);
1265    
1266                                    count = (Long)q.uniqueResult();
1267                            }
1268                            catch (Exception e) {
1269                                    throw processException(e);
1270                            }
1271                            finally {
1272                                    if (count == null) {
1273                                            count = Long.valueOf(0);
1274                                    }
1275    
1276                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
1277                                            finderArgs, count);
1278    
1279                                    closeSession(session);
1280                            }
1281                    }
1282    
1283                    return count.intValue();
1284            }
1285    
1286            /**
1287             * Counts all the layout sets where virtualHost = &#63;.
1288             *
1289             * @param virtualHost the virtual host to search with
1290             * @return the number of matching layout sets
1291             * @throws SystemException if a system exception occurred
1292             */
1293            public int countByVirtualHost(String virtualHost) throws SystemException {
1294                    Object[] finderArgs = new Object[] { virtualHost };
1295    
1296                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_VIRTUALHOST,
1297                                    finderArgs, this);
1298    
1299                    if (count == null) {
1300                            Session session = null;
1301    
1302                            try {
1303                                    session = openSession();
1304    
1305                                    StringBundler query = new StringBundler(2);
1306    
1307                                    query.append(_SQL_COUNT_LAYOUTSET_WHERE);
1308    
1309                                    if (virtualHost == null) {
1310                                            query.append(_FINDER_COLUMN_VIRTUALHOST_VIRTUALHOST_1);
1311                                    }
1312                                    else {
1313                                            if (virtualHost.equals(StringPool.BLANK)) {
1314                                                    query.append(_FINDER_COLUMN_VIRTUALHOST_VIRTUALHOST_3);
1315                                            }
1316                                            else {
1317                                                    query.append(_FINDER_COLUMN_VIRTUALHOST_VIRTUALHOST_2);
1318                                            }
1319                                    }
1320    
1321                                    String sql = query.toString();
1322    
1323                                    Query q = session.createQuery(sql);
1324    
1325                                    QueryPos qPos = QueryPos.getInstance(q);
1326    
1327                                    if (virtualHost != null) {
1328                                            qPos.add(virtualHost);
1329                                    }
1330    
1331                                    count = (Long)q.uniqueResult();
1332                            }
1333                            catch (Exception e) {
1334                                    throw processException(e);
1335                            }
1336                            finally {
1337                                    if (count == null) {
1338                                            count = Long.valueOf(0);
1339                                    }
1340    
1341                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_VIRTUALHOST,
1342                                            finderArgs, count);
1343    
1344                                    closeSession(session);
1345                            }
1346                    }
1347    
1348                    return count.intValue();
1349            }
1350    
1351            /**
1352             * Counts all the layout sets where groupId = &#63; and privateLayout = &#63;.
1353             *
1354             * @param groupId the group id to search with
1355             * @param privateLayout the private layout to search with
1356             * @return the number of matching layout sets
1357             * @throws SystemException if a system exception occurred
1358             */
1359            public int countByG_P(long groupId, boolean privateLayout)
1360                    throws SystemException {
1361                    Object[] finderArgs = new Object[] { groupId, privateLayout };
1362    
1363                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_P,
1364                                    finderArgs, this);
1365    
1366                    if (count == null) {
1367                            Session session = null;
1368    
1369                            try {
1370                                    session = openSession();
1371    
1372                                    StringBundler query = new StringBundler(3);
1373    
1374                                    query.append(_SQL_COUNT_LAYOUTSET_WHERE);
1375    
1376                                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
1377    
1378                                    query.append(_FINDER_COLUMN_G_P_PRIVATELAYOUT_2);
1379    
1380                                    String sql = query.toString();
1381    
1382                                    Query q = session.createQuery(sql);
1383    
1384                                    QueryPos qPos = QueryPos.getInstance(q);
1385    
1386                                    qPos.add(groupId);
1387    
1388                                    qPos.add(privateLayout);
1389    
1390                                    count = (Long)q.uniqueResult();
1391                            }
1392                            catch (Exception e) {
1393                                    throw processException(e);
1394                            }
1395                            finally {
1396                                    if (count == null) {
1397                                            count = Long.valueOf(0);
1398                                    }
1399    
1400                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_P, finderArgs,
1401                                            count);
1402    
1403                                    closeSession(session);
1404                            }
1405                    }
1406    
1407                    return count.intValue();
1408            }
1409    
1410            /**
1411             * Counts all the layout sets.
1412             *
1413             * @return the number of layout sets
1414             * @throws SystemException if a system exception occurred
1415             */
1416            public int countAll() throws SystemException {
1417                    Object[] finderArgs = new Object[0];
1418    
1419                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1420                                    finderArgs, this);
1421    
1422                    if (count == null) {
1423                            Session session = null;
1424    
1425                            try {
1426                                    session = openSession();
1427    
1428                                    Query q = session.createQuery(_SQL_COUNT_LAYOUTSET);
1429    
1430                                    count = (Long)q.uniqueResult();
1431                            }
1432                            catch (Exception e) {
1433                                    throw processException(e);
1434                            }
1435                            finally {
1436                                    if (count == null) {
1437                                            count = Long.valueOf(0);
1438                                    }
1439    
1440                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1441                                            count);
1442    
1443                                    closeSession(session);
1444                            }
1445                    }
1446    
1447                    return count.intValue();
1448            }
1449    
1450            /**
1451             * Initializes the layout set persistence.
1452             */
1453            public void afterPropertiesSet() {
1454                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1455                                            com.liferay.portal.util.PropsUtil.get(
1456                                                    "value.object.listener.com.liferay.portal.model.LayoutSet")));
1457    
1458                    if (listenerClassNames.length > 0) {
1459                            try {
1460                                    List<ModelListener<LayoutSet>> listenersList = new ArrayList<ModelListener<LayoutSet>>();
1461    
1462                                    for (String listenerClassName : listenerClassNames) {
1463                                            listenersList.add((ModelListener<LayoutSet>)InstanceFactory.newInstance(
1464                                                            listenerClassName));
1465                                    }
1466    
1467                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1468                            }
1469                            catch (Exception e) {
1470                                    _log.error(e);
1471                            }
1472                    }
1473            }
1474    
1475            @BeanReference(type = AccountPersistence.class)
1476            protected AccountPersistence accountPersistence;
1477            @BeanReference(type = AddressPersistence.class)
1478            protected AddressPersistence addressPersistence;
1479            @BeanReference(type = BrowserTrackerPersistence.class)
1480            protected BrowserTrackerPersistence browserTrackerPersistence;
1481            @BeanReference(type = ClassNamePersistence.class)
1482            protected ClassNamePersistence classNamePersistence;
1483            @BeanReference(type = CompanyPersistence.class)
1484            protected CompanyPersistence companyPersistence;
1485            @BeanReference(type = ContactPersistence.class)
1486            protected ContactPersistence contactPersistence;
1487            @BeanReference(type = CountryPersistence.class)
1488            protected CountryPersistence countryPersistence;
1489            @BeanReference(type = EmailAddressPersistence.class)
1490            protected EmailAddressPersistence emailAddressPersistence;
1491            @BeanReference(type = GroupPersistence.class)
1492            protected GroupPersistence groupPersistence;
1493            @BeanReference(type = ImagePersistence.class)
1494            protected ImagePersistence imagePersistence;
1495            @BeanReference(type = LayoutPersistence.class)
1496            protected LayoutPersistence layoutPersistence;
1497            @BeanReference(type = LayoutPrototypePersistence.class)
1498            protected LayoutPrototypePersistence layoutPrototypePersistence;
1499            @BeanReference(type = LayoutSetPersistence.class)
1500            protected LayoutSetPersistence layoutSetPersistence;
1501            @BeanReference(type = LayoutSetPrototypePersistence.class)
1502            protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
1503            @BeanReference(type = ListTypePersistence.class)
1504            protected ListTypePersistence listTypePersistence;
1505            @BeanReference(type = LockPersistence.class)
1506            protected LockPersistence lockPersistence;
1507            @BeanReference(type = MembershipRequestPersistence.class)
1508            protected MembershipRequestPersistence membershipRequestPersistence;
1509            @BeanReference(type = OrganizationPersistence.class)
1510            protected OrganizationPersistence organizationPersistence;
1511            @BeanReference(type = OrgGroupPermissionPersistence.class)
1512            protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1513            @BeanReference(type = OrgGroupRolePersistence.class)
1514            protected OrgGroupRolePersistence orgGroupRolePersistence;
1515            @BeanReference(type = OrgLaborPersistence.class)
1516            protected OrgLaborPersistence orgLaborPersistence;
1517            @BeanReference(type = PasswordPolicyPersistence.class)
1518            protected PasswordPolicyPersistence passwordPolicyPersistence;
1519            @BeanReference(type = PasswordPolicyRelPersistence.class)
1520            protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1521            @BeanReference(type = PasswordTrackerPersistence.class)
1522            protected PasswordTrackerPersistence passwordTrackerPersistence;
1523            @BeanReference(type = PermissionPersistence.class)
1524            protected PermissionPersistence permissionPersistence;
1525            @BeanReference(type = PhonePersistence.class)
1526            protected PhonePersistence phonePersistence;
1527            @BeanReference(type = PluginSettingPersistence.class)
1528            protected PluginSettingPersistence pluginSettingPersistence;
1529            @BeanReference(type = PortletPersistence.class)
1530            protected PortletPersistence portletPersistence;
1531            @BeanReference(type = PortletItemPersistence.class)
1532            protected PortletItemPersistence portletItemPersistence;
1533            @BeanReference(type = PortletPreferencesPersistence.class)
1534            protected PortletPreferencesPersistence portletPreferencesPersistence;
1535            @BeanReference(type = RegionPersistence.class)
1536            protected RegionPersistence regionPersistence;
1537            @BeanReference(type = ReleasePersistence.class)
1538            protected ReleasePersistence releasePersistence;
1539            @BeanReference(type = ResourcePersistence.class)
1540            protected ResourcePersistence resourcePersistence;
1541            @BeanReference(type = ResourceActionPersistence.class)
1542            protected ResourceActionPersistence resourceActionPersistence;
1543            @BeanReference(type = ResourceCodePersistence.class)
1544            protected ResourceCodePersistence resourceCodePersistence;
1545            @BeanReference(type = ResourcePermissionPersistence.class)
1546            protected ResourcePermissionPersistence resourcePermissionPersistence;
1547            @BeanReference(type = RolePersistence.class)
1548            protected RolePersistence rolePersistence;
1549            @BeanReference(type = ServiceComponentPersistence.class)
1550            protected ServiceComponentPersistence serviceComponentPersistence;
1551            @BeanReference(type = ShardPersistence.class)
1552            protected ShardPersistence shardPersistence;
1553            @BeanReference(type = SubscriptionPersistence.class)
1554            protected SubscriptionPersistence subscriptionPersistence;
1555            @BeanReference(type = TicketPersistence.class)
1556            protected TicketPersistence ticketPersistence;
1557            @BeanReference(type = TeamPersistence.class)
1558            protected TeamPersistence teamPersistence;
1559            @BeanReference(type = UserPersistence.class)
1560            protected UserPersistence userPersistence;
1561            @BeanReference(type = UserGroupPersistence.class)
1562            protected UserGroupPersistence userGroupPersistence;
1563            @BeanReference(type = UserGroupGroupRolePersistence.class)
1564            protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1565            @BeanReference(type = UserGroupRolePersistence.class)
1566            protected UserGroupRolePersistence userGroupRolePersistence;
1567            @BeanReference(type = UserIdMapperPersistence.class)
1568            protected UserIdMapperPersistence userIdMapperPersistence;
1569            @BeanReference(type = UserTrackerPersistence.class)
1570            protected UserTrackerPersistence userTrackerPersistence;
1571            @BeanReference(type = UserTrackerPathPersistence.class)
1572            protected UserTrackerPathPersistence userTrackerPathPersistence;
1573            @BeanReference(type = WebDAVPropsPersistence.class)
1574            protected WebDAVPropsPersistence webDAVPropsPersistence;
1575            @BeanReference(type = WebsitePersistence.class)
1576            protected WebsitePersistence websitePersistence;
1577            @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
1578            protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
1579            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
1580            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
1581            private static final String _SQL_SELECT_LAYOUTSET = "SELECT layoutSet FROM LayoutSet layoutSet";
1582            private static final String _SQL_SELECT_LAYOUTSET_WHERE = "SELECT layoutSet FROM LayoutSet layoutSet WHERE ";
1583            private static final String _SQL_COUNT_LAYOUTSET = "SELECT COUNT(layoutSet) FROM LayoutSet layoutSet";
1584            private static final String _SQL_COUNT_LAYOUTSET_WHERE = "SELECT COUNT(layoutSet) FROM LayoutSet layoutSet WHERE ";
1585            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "layoutSet.groupId = ?";
1586            private static final String _FINDER_COLUMN_VIRTUALHOST_VIRTUALHOST_1 = "layoutSet.virtualHost IS NULL";
1587            private static final String _FINDER_COLUMN_VIRTUALHOST_VIRTUALHOST_2 = "layoutSet.virtualHost = ?";
1588            private static final String _FINDER_COLUMN_VIRTUALHOST_VIRTUALHOST_3 = "(layoutSet.virtualHost IS NULL OR layoutSet.virtualHost = ?)";
1589            private static final String _FINDER_COLUMN_G_P_GROUPID_2 = "layoutSet.groupId = ? AND ";
1590            private static final String _FINDER_COLUMN_G_P_PRIVATELAYOUT_2 = "layoutSet.privateLayout = ?";
1591            private static final String _ORDER_BY_ENTITY_ALIAS = "layoutSet.";
1592            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No LayoutSet exists with the primary key ";
1593            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No LayoutSet exists with the key {";
1594            private static Log _log = LogFactoryUtil.getLog(LayoutSetPersistenceImpl.class);
1595    }