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