001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.service.persistence;
016    
017    import com.liferay.portal.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.getOriginalVirtualHost() });
265    
266                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P,
267                            new Object[] {
268                                    new Long(layoutSetModelImpl.getOriginalGroupId()),
269                                    Boolean.valueOf(layoutSetModelImpl.getOriginalPrivateLayout())
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                            Session session = null;
517    
518                            try {
519                                    session = openSession();
520    
521                                    StringBundler query = null;
522    
523                                    if (orderByComparator != null) {
524                                            query = new StringBundler(3 +
525                                                            (orderByComparator.getOrderByFields().length * 3));
526                                    }
527                                    else {
528                                            query = new StringBundler(2);
529                                    }
530    
531                                    query.append(_SQL_SELECT_LAYOUTSET_WHERE);
532    
533                                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
534    
535                                    if (orderByComparator != null) {
536                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
537                                                    orderByComparator);
538                                    }
539    
540                                    String sql = query.toString();
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                                            list = new ArrayList<LayoutSet>();
557                                    }
558    
559                                    cacheResult(list);
560    
561                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
562                                            finderArgs, list);
563    
564                                    closeSession(session);
565                            }
566                    }
567    
568                    return list;
569            }
570    
571            /**
572             * Finds the first layout set in the ordered set where groupId = &#63;.
573             *
574             * <p>
575             * 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.
576             * </p>
577             *
578             * @param groupId the group id to search with
579             * @param orderByComparator the comparator to order the set by
580             * @return the first matching layout set
581             * @throws com.liferay.portal.NoSuchLayoutSetException if a matching layout set could not be found
582             * @throws SystemException if a system exception occurred
583             */
584            public LayoutSet findByGroupId_First(long groupId,
585                    OrderByComparator orderByComparator)
586                    throws NoSuchLayoutSetException, SystemException {
587                    List<LayoutSet> list = findByGroupId(groupId, 0, 1, orderByComparator);
588    
589                    if (list.isEmpty()) {
590                            StringBundler msg = new StringBundler(4);
591    
592                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
593    
594                            msg.append("groupId=");
595                            msg.append(groupId);
596    
597                            msg.append(StringPool.CLOSE_CURLY_BRACE);
598    
599                            throw new NoSuchLayoutSetException(msg.toString());
600                    }
601                    else {
602                            return list.get(0);
603                    }
604            }
605    
606            /**
607             * Finds the last layout set in the ordered set where groupId = &#63;.
608             *
609             * <p>
610             * 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.
611             * </p>
612             *
613             * @param groupId the group id to search with
614             * @param orderByComparator the comparator to order the set by
615             * @return the last matching layout set
616             * @throws com.liferay.portal.NoSuchLayoutSetException if a matching layout set could not be found
617             * @throws SystemException if a system exception occurred
618             */
619            public LayoutSet findByGroupId_Last(long groupId,
620                    OrderByComparator orderByComparator)
621                    throws NoSuchLayoutSetException, SystemException {
622                    int count = countByGroupId(groupId);
623    
624                    List<LayoutSet> list = findByGroupId(groupId, count - 1, count,
625                                    orderByComparator);
626    
627                    if (list.isEmpty()) {
628                            StringBundler msg = new StringBundler(4);
629    
630                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
631    
632                            msg.append("groupId=");
633                            msg.append(groupId);
634    
635                            msg.append(StringPool.CLOSE_CURLY_BRACE);
636    
637                            throw new NoSuchLayoutSetException(msg.toString());
638                    }
639                    else {
640                            return list.get(0);
641                    }
642            }
643    
644            /**
645             * Finds the layout sets before and after the current layout set in the ordered set where groupId = &#63;.
646             *
647             * <p>
648             * 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.
649             * </p>
650             *
651             * @param layoutSetId the primary key of the current layout set
652             * @param groupId the group id to search with
653             * @param orderByComparator the comparator to order the set by
654             * @return the previous, current, and next layout set
655             * @throws com.liferay.portal.NoSuchLayoutSetException if a layout set with the primary key could not be found
656             * @throws SystemException if a system exception occurred
657             */
658            public LayoutSet[] findByGroupId_PrevAndNext(long layoutSetId,
659                    long groupId, OrderByComparator orderByComparator)
660                    throws NoSuchLayoutSetException, SystemException {
661                    LayoutSet layoutSet = findByPrimaryKey(layoutSetId);
662    
663                    Session session = null;
664    
665                    try {
666                            session = openSession();
667    
668                            LayoutSet[] array = new LayoutSetImpl[3];
669    
670                            array[0] = getByGroupId_PrevAndNext(session, layoutSet, groupId,
671                                            orderByComparator, true);
672    
673                            array[1] = layoutSet;
674    
675                            array[2] = getByGroupId_PrevAndNext(session, layoutSet, groupId,
676                                            orderByComparator, false);
677    
678                            return array;
679                    }
680                    catch (Exception e) {
681                            throw processException(e);
682                    }
683                    finally {
684                            closeSession(session);
685                    }
686            }
687    
688            protected LayoutSet getByGroupId_PrevAndNext(Session session,
689                    LayoutSet layoutSet, long groupId, OrderByComparator orderByComparator,
690                    boolean previous) {
691                    StringBundler query = null;
692    
693                    if (orderByComparator != null) {
694                            query = new StringBundler(6 +
695                                            (orderByComparator.getOrderByFields().length * 6));
696                    }
697                    else {
698                            query = new StringBundler(3);
699                    }
700    
701                    query.append(_SQL_SELECT_LAYOUTSET_WHERE);
702    
703                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
704    
705                    if (orderByComparator != null) {
706                            String[] orderByFields = orderByComparator.getOrderByFields();
707    
708                            if (orderByFields.length > 0) {
709                                    query.append(WHERE_AND);
710                            }
711    
712                            for (int i = 0; i < orderByFields.length; i++) {
713                                    query.append(_ORDER_BY_ENTITY_ALIAS);
714                                    query.append(orderByFields[i]);
715    
716                                    if ((i + 1) < orderByFields.length) {
717                                            if (orderByComparator.isAscending() ^ previous) {
718                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
719                                            }
720                                            else {
721                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
722                                            }
723                                    }
724                                    else {
725                                            if (orderByComparator.isAscending() ^ previous) {
726                                                    query.append(WHERE_GREATER_THAN);
727                                            }
728                                            else {
729                                                    query.append(WHERE_LESSER_THAN);
730                                            }
731                                    }
732                            }
733    
734                            query.append(ORDER_BY_CLAUSE);
735    
736                            for (int i = 0; i < orderByFields.length; i++) {
737                                    query.append(_ORDER_BY_ENTITY_ALIAS);
738                                    query.append(orderByFields[i]);
739    
740                                    if ((i + 1) < orderByFields.length) {
741                                            if (orderByComparator.isAscending() ^ previous) {
742                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
743                                            }
744                                            else {
745                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
746                                            }
747                                    }
748                                    else {
749                                            if (orderByComparator.isAscending() ^ previous) {
750                                                    query.append(ORDER_BY_ASC);
751                                            }
752                                            else {
753                                                    query.append(ORDER_BY_DESC);
754                                            }
755                                    }
756                            }
757                    }
758    
759                    String sql = query.toString();
760    
761                    Query q = session.createQuery(sql);
762    
763                    q.setFirstResult(0);
764                    q.setMaxResults(2);
765    
766                    QueryPos qPos = QueryPos.getInstance(q);
767    
768                    qPos.add(groupId);
769    
770                    if (orderByComparator != null) {
771                            Object[] values = orderByComparator.getOrderByValues(layoutSet);
772    
773                            for (Object value : values) {
774                                    qPos.add(value);
775                            }
776                    }
777    
778                    List<LayoutSet> list = q.list();
779    
780                    if (list.size() == 2) {
781                            return list.get(1);
782                    }
783                    else {
784                            return null;
785                    }
786            }
787    
788            /**
789             * Finds the layout set where virtualHost = &#63; or throws a {@link com.liferay.portal.NoSuchLayoutSetException} if it could not be found.
790             *
791             * @param virtualHost the virtual host to search with
792             * @return the matching layout set
793             * @throws com.liferay.portal.NoSuchLayoutSetException if a matching layout set could not be found
794             * @throws SystemException if a system exception occurred
795             */
796            public LayoutSet findByVirtualHost(String virtualHost)
797                    throws NoSuchLayoutSetException, SystemException {
798                    LayoutSet layoutSet = fetchByVirtualHost(virtualHost);
799    
800                    if (layoutSet == null) {
801                            StringBundler msg = new StringBundler(4);
802    
803                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
804    
805                            msg.append("virtualHost=");
806                            msg.append(virtualHost);
807    
808                            msg.append(StringPool.CLOSE_CURLY_BRACE);
809    
810                            if (_log.isWarnEnabled()) {
811                                    _log.warn(msg.toString());
812                            }
813    
814                            throw new NoSuchLayoutSetException(msg.toString());
815                    }
816    
817                    return layoutSet;
818            }
819    
820            /**
821             * Finds the layout set where virtualHost = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
822             *
823             * @param virtualHost the virtual host to search with
824             * @return the matching layout set, or <code>null</code> if a matching layout set could not be found
825             * @throws SystemException if a system exception occurred
826             */
827            public LayoutSet fetchByVirtualHost(String virtualHost)
828                    throws SystemException {
829                    return fetchByVirtualHost(virtualHost, true);
830            }
831    
832            /**
833             * Finds the layout set where virtualHost = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
834             *
835             * @param virtualHost the virtual host to search with
836             * @return the matching layout set, or <code>null</code> if a matching layout set could not be found
837             * @throws SystemException if a system exception occurred
838             */
839            public LayoutSet fetchByVirtualHost(String virtualHost,
840                    boolean retrieveFromCache) throws SystemException {
841                    Object[] finderArgs = new Object[] { virtualHost };
842    
843                    Object result = null;
844    
845                    if (retrieveFromCache) {
846                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_VIRTUALHOST,
847                                            finderArgs, this);
848                    }
849    
850                    if (result == null) {
851                            Session session = null;
852    
853                            try {
854                                    session = openSession();
855    
856                                    StringBundler query = new StringBundler(2);
857    
858                                    query.append(_SQL_SELECT_LAYOUTSET_WHERE);
859    
860                                    if (virtualHost == null) {
861                                            query.append(_FINDER_COLUMN_VIRTUALHOST_VIRTUALHOST_1);
862                                    }
863                                    else {
864                                            if (virtualHost.equals(StringPool.BLANK)) {
865                                                    query.append(_FINDER_COLUMN_VIRTUALHOST_VIRTUALHOST_3);
866                                            }
867                                            else {
868                                                    query.append(_FINDER_COLUMN_VIRTUALHOST_VIRTUALHOST_2);
869                                            }
870                                    }
871    
872                                    String sql = query.toString();
873    
874                                    Query q = session.createQuery(sql);
875    
876                                    QueryPos qPos = QueryPos.getInstance(q);
877    
878                                    if (virtualHost != null) {
879                                            qPos.add(virtualHost);
880                                    }
881    
882                                    List<LayoutSet> list = q.list();
883    
884                                    result = list;
885    
886                                    LayoutSet layoutSet = null;
887    
888                                    if (list.isEmpty()) {
889                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_VIRTUALHOST,
890                                                    finderArgs, list);
891                                    }
892                                    else {
893                                            layoutSet = list.get(0);
894    
895                                            cacheResult(layoutSet);
896    
897                                            if ((layoutSet.getVirtualHost() == null) ||
898                                                            !layoutSet.getVirtualHost().equals(virtualHost)) {
899                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_VIRTUALHOST,
900                                                            finderArgs, layoutSet);
901                                            }
902                                    }
903    
904                                    return layoutSet;
905                            }
906                            catch (Exception e) {
907                                    throw processException(e);
908                            }
909                            finally {
910                                    if (result == null) {
911                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_VIRTUALHOST,
912                                                    finderArgs, new ArrayList<LayoutSet>());
913                                    }
914    
915                                    closeSession(session);
916                            }
917                    }
918                    else {
919                            if (result instanceof List<?>) {
920                                    return null;
921                            }
922                            else {
923                                    return (LayoutSet)result;
924                            }
925                    }
926            }
927    
928            /**
929             * Finds the layout set where groupId = &#63; and privateLayout = &#63; or throws a {@link com.liferay.portal.NoSuchLayoutSetException} if it could not be found.
930             *
931             * @param groupId the group id to search with
932             * @param privateLayout the private layout to search with
933             * @return the matching layout set
934             * @throws com.liferay.portal.NoSuchLayoutSetException if a matching layout set could not be found
935             * @throws SystemException if a system exception occurred
936             */
937            public LayoutSet findByG_P(long groupId, boolean privateLayout)
938                    throws NoSuchLayoutSetException, SystemException {
939                    LayoutSet layoutSet = fetchByG_P(groupId, privateLayout);
940    
941                    if (layoutSet == null) {
942                            StringBundler msg = new StringBundler(6);
943    
944                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
945    
946                            msg.append("groupId=");
947                            msg.append(groupId);
948    
949                            msg.append(", privateLayout=");
950                            msg.append(privateLayout);
951    
952                            msg.append(StringPool.CLOSE_CURLY_BRACE);
953    
954                            if (_log.isWarnEnabled()) {
955                                    _log.warn(msg.toString());
956                            }
957    
958                            throw new NoSuchLayoutSetException(msg.toString());
959                    }
960    
961                    return layoutSet;
962            }
963    
964            /**
965             * 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.
966             *
967             * @param groupId the group id to search with
968             * @param privateLayout the private layout to search with
969             * @return the matching layout set, or <code>null</code> if a matching layout set could not be found
970             * @throws SystemException if a system exception occurred
971             */
972            public LayoutSet fetchByG_P(long groupId, boolean privateLayout)
973                    throws SystemException {
974                    return fetchByG_P(groupId, privateLayout, true);
975            }
976    
977            /**
978             * 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.
979             *
980             * @param groupId the group id to search with
981             * @param privateLayout the private layout to search with
982             * @return the matching layout set, or <code>null</code> if a matching layout set could not be found
983             * @throws SystemException if a system exception occurred
984             */
985            public LayoutSet fetchByG_P(long groupId, boolean privateLayout,
986                    boolean retrieveFromCache) throws SystemException {
987                    Object[] finderArgs = new Object[] { groupId, privateLayout };
988    
989                    Object result = null;
990    
991                    if (retrieveFromCache) {
992                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_P,
993                                            finderArgs, this);
994                    }
995    
996                    if (result == null) {
997                            Session session = null;
998    
999                            try {
1000                                    session = openSession();
1001    
1002                                    StringBundler query = new StringBundler(3);
1003    
1004                                    query.append(_SQL_SELECT_LAYOUTSET_WHERE);
1005    
1006                                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
1007    
1008                                    query.append(_FINDER_COLUMN_G_P_PRIVATELAYOUT_2);
1009    
1010                                    String sql = query.toString();
1011    
1012                                    Query q = session.createQuery(sql);
1013    
1014                                    QueryPos qPos = QueryPos.getInstance(q);
1015    
1016                                    qPos.add(groupId);
1017    
1018                                    qPos.add(privateLayout);
1019    
1020                                    List<LayoutSet> list = q.list();
1021    
1022                                    result = list;
1023    
1024                                    LayoutSet layoutSet = null;
1025    
1026                                    if (list.isEmpty()) {
1027                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P,
1028                                                    finderArgs, list);
1029                                    }
1030                                    else {
1031                                            layoutSet = list.get(0);
1032    
1033                                            cacheResult(layoutSet);
1034    
1035                                            if ((layoutSet.getGroupId() != groupId) ||
1036                                                            (layoutSet.getPrivateLayout() != privateLayout)) {
1037                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P,
1038                                                            finderArgs, layoutSet);
1039                                            }
1040                                    }
1041    
1042                                    return layoutSet;
1043                            }
1044                            catch (Exception e) {
1045                                    throw processException(e);
1046                            }
1047                            finally {
1048                                    if (result == null) {
1049                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P,
1050                                                    finderArgs, new ArrayList<LayoutSet>());
1051                                    }
1052    
1053                                    closeSession(session);
1054                            }
1055                    }
1056                    else {
1057                            if (result instanceof List<?>) {
1058                                    return null;
1059                            }
1060                            else {
1061                                    return (LayoutSet)result;
1062                            }
1063                    }
1064            }
1065    
1066            /**
1067             * Finds all the layout sets.
1068             *
1069             * @return the layout sets
1070             * @throws SystemException if a system exception occurred
1071             */
1072            public List<LayoutSet> findAll() throws SystemException {
1073                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1074            }
1075    
1076            /**
1077             * Finds a range of all the layout sets.
1078             *
1079             * <p>
1080             * 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.
1081             * </p>
1082             *
1083             * @param start the lower bound of the range of layout sets to return
1084             * @param end the upper bound of the range of layout sets to return (not inclusive)
1085             * @return the range of layout sets
1086             * @throws SystemException if a system exception occurred
1087             */
1088            public List<LayoutSet> findAll(int start, int end)
1089                    throws SystemException {
1090                    return findAll(start, end, null);
1091            }
1092    
1093            /**
1094             * Finds an ordered range of all the layout sets.
1095             *
1096             * <p>
1097             * 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.
1098             * </p>
1099             *
1100             * @param start the lower bound of the range of layout sets to return
1101             * @param end the upper bound of the range of layout sets to return (not inclusive)
1102             * @param orderByComparator the comparator to order the results by
1103             * @return the ordered range of layout sets
1104             * @throws SystemException if a system exception occurred
1105             */
1106            public List<LayoutSet> findAll(int start, int end,
1107                    OrderByComparator orderByComparator) throws SystemException {
1108                    Object[] finderArgs = new Object[] {
1109                                    String.valueOf(start), String.valueOf(end),
1110                                    String.valueOf(orderByComparator)
1111                            };
1112    
1113                    List<LayoutSet> list = (List<LayoutSet>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1114                                    finderArgs, this);
1115    
1116                    if (list == null) {
1117                            Session session = null;
1118    
1119                            try {
1120                                    session = openSession();
1121    
1122                                    StringBundler query = null;
1123                                    String sql = null;
1124    
1125                                    if (orderByComparator != null) {
1126                                            query = new StringBundler(2 +
1127                                                            (orderByComparator.getOrderByFields().length * 3));
1128    
1129                                            query.append(_SQL_SELECT_LAYOUTSET);
1130    
1131                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1132                                                    orderByComparator);
1133    
1134                                            sql = query.toString();
1135                                    }
1136                                    else {
1137                                            sql = _SQL_SELECT_LAYOUTSET;
1138                                    }
1139    
1140                                    Query q = session.createQuery(sql);
1141    
1142                                    if (orderByComparator == null) {
1143                                            list = (List<LayoutSet>)QueryUtil.list(q, getDialect(),
1144                                                            start, end, false);
1145    
1146                                            Collections.sort(list);
1147                                    }
1148                                    else {
1149                                            list = (List<LayoutSet>)QueryUtil.list(q, getDialect(),
1150                                                            start, end);
1151                                    }
1152                            }
1153                            catch (Exception e) {
1154                                    throw processException(e);
1155                            }
1156                            finally {
1157                                    if (list == null) {
1158                                            list = new ArrayList<LayoutSet>();
1159                                    }
1160    
1161                                    cacheResult(list);
1162    
1163                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1164    
1165                                    closeSession(session);
1166                            }
1167                    }
1168    
1169                    return list;
1170            }
1171    
1172            /**
1173             * Removes all the layout sets where groupId = &#63; from the database.
1174             *
1175             * @param groupId the group id to search with
1176             * @throws SystemException if a system exception occurred
1177             */
1178            public void removeByGroupId(long groupId) throws SystemException {
1179                    for (LayoutSet layoutSet : findByGroupId(groupId)) {
1180                            remove(layoutSet);
1181                    }
1182            }
1183    
1184            /**
1185             * Removes the layout set where virtualHost = &#63; from the database.
1186             *
1187             * @param virtualHost the virtual host to search with
1188             * @throws SystemException if a system exception occurred
1189             */
1190            public void removeByVirtualHost(String virtualHost)
1191                    throws NoSuchLayoutSetException, SystemException {
1192                    LayoutSet layoutSet = findByVirtualHost(virtualHost);
1193    
1194                    remove(layoutSet);
1195            }
1196    
1197            /**
1198             * Removes the layout set where groupId = &#63; and privateLayout = &#63; from the database.
1199             *
1200             * @param groupId the group id to search with
1201             * @param privateLayout the private layout to search with
1202             * @throws SystemException if a system exception occurred
1203             */
1204            public void removeByG_P(long groupId, boolean privateLayout)
1205                    throws NoSuchLayoutSetException, SystemException {
1206                    LayoutSet layoutSet = findByG_P(groupId, privateLayout);
1207    
1208                    remove(layoutSet);
1209            }
1210    
1211            /**
1212             * Removes all the layout sets from the database.
1213             *
1214             * @throws SystemException if a system exception occurred
1215             */
1216            public void removeAll() throws SystemException {
1217                    for (LayoutSet layoutSet : findAll()) {
1218                            remove(layoutSet);
1219                    }
1220            }
1221    
1222            /**
1223             * Counts all the layout sets where groupId = &#63;.
1224             *
1225             * @param groupId the group id to search with
1226             * @return the number of matching layout sets
1227             * @throws SystemException if a system exception occurred
1228             */
1229            public int countByGroupId(long groupId) throws SystemException {
1230                    Object[] finderArgs = new Object[] { groupId };
1231    
1232                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
1233                                    finderArgs, this);
1234    
1235                    if (count == null) {
1236                            Session session = null;
1237    
1238                            try {
1239                                    session = openSession();
1240    
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                                    Query q = session.createQuery(sql);
1250    
1251                                    QueryPos qPos = QueryPos.getInstance(q);
1252    
1253                                    qPos.add(groupId);
1254    
1255                                    count = (Long)q.uniqueResult();
1256                            }
1257                            catch (Exception e) {
1258                                    throw processException(e);
1259                            }
1260                            finally {
1261                                    if (count == null) {
1262                                            count = Long.valueOf(0);
1263                                    }
1264    
1265                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
1266                                            finderArgs, count);
1267    
1268                                    closeSession(session);
1269                            }
1270                    }
1271    
1272                    return count.intValue();
1273            }
1274    
1275            /**
1276             * Counts all the layout sets where virtualHost = &#63;.
1277             *
1278             * @param virtualHost the virtual host to search with
1279             * @return the number of matching layout sets
1280             * @throws SystemException if a system exception occurred
1281             */
1282            public int countByVirtualHost(String virtualHost) throws SystemException {
1283                    Object[] finderArgs = new Object[] { virtualHost };
1284    
1285                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_VIRTUALHOST,
1286                                    finderArgs, this);
1287    
1288                    if (count == null) {
1289                            Session session = null;
1290    
1291                            try {
1292                                    session = openSession();
1293    
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                                    Query q = session.createQuery(sql);
1313    
1314                                    QueryPos qPos = QueryPos.getInstance(q);
1315    
1316                                    if (virtualHost != null) {
1317                                            qPos.add(virtualHost);
1318                                    }
1319    
1320                                    count = (Long)q.uniqueResult();
1321                            }
1322                            catch (Exception e) {
1323                                    throw processException(e);
1324                            }
1325                            finally {
1326                                    if (count == null) {
1327                                            count = Long.valueOf(0);
1328                                    }
1329    
1330                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_VIRTUALHOST,
1331                                            finderArgs, count);
1332    
1333                                    closeSession(session);
1334                            }
1335                    }
1336    
1337                    return count.intValue();
1338            }
1339    
1340            /**
1341             * Counts all the layout sets where groupId = &#63; and privateLayout = &#63;.
1342             *
1343             * @param groupId the group id to search with
1344             * @param privateLayout the private layout to search with
1345             * @return the number of matching layout sets
1346             * @throws SystemException if a system exception occurred
1347             */
1348            public int countByG_P(long groupId, boolean privateLayout)
1349                    throws SystemException {
1350                    Object[] finderArgs = new Object[] { groupId, privateLayout };
1351    
1352                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_P,
1353                                    finderArgs, this);
1354    
1355                    if (count == null) {
1356                            Session session = null;
1357    
1358                            try {
1359                                    session = openSession();
1360    
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                                    Query q = session.createQuery(sql);
1372    
1373                                    QueryPos qPos = QueryPos.getInstance(q);
1374    
1375                                    qPos.add(groupId);
1376    
1377                                    qPos.add(privateLayout);
1378    
1379                                    count = (Long)q.uniqueResult();
1380                            }
1381                            catch (Exception e) {
1382                                    throw processException(e);
1383                            }
1384                            finally {
1385                                    if (count == null) {
1386                                            count = Long.valueOf(0);
1387                                    }
1388    
1389                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_P, finderArgs,
1390                                            count);
1391    
1392                                    closeSession(session);
1393                            }
1394                    }
1395    
1396                    return count.intValue();
1397            }
1398    
1399            /**
1400             * Counts all the layout sets.
1401             *
1402             * @return the number of layout sets
1403             * @throws SystemException if a system exception occurred
1404             */
1405            public int countAll() throws SystemException {
1406                    Object[] finderArgs = new Object[0];
1407    
1408                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1409                                    finderArgs, this);
1410    
1411                    if (count == null) {
1412                            Session session = null;
1413    
1414                            try {
1415                                    session = openSession();
1416    
1417                                    Query q = session.createQuery(_SQL_COUNT_LAYOUTSET);
1418    
1419                                    count = (Long)q.uniqueResult();
1420                            }
1421                            catch (Exception e) {
1422                                    throw processException(e);
1423                            }
1424                            finally {
1425                                    if (count == null) {
1426                                            count = Long.valueOf(0);
1427                                    }
1428    
1429                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1430                                            count);
1431    
1432                                    closeSession(session);
1433                            }
1434                    }
1435    
1436                    return count.intValue();
1437            }
1438    
1439            /**
1440             * Initializes the layout set persistence.
1441             */
1442            public void afterPropertiesSet() {
1443                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1444                                            com.liferay.portal.util.PropsUtil.get(
1445                                                    "value.object.listener.com.liferay.portal.model.LayoutSet")));
1446    
1447                    if (listenerClassNames.length > 0) {
1448                            try {
1449                                    List<ModelListener<LayoutSet>> listenersList = new ArrayList<ModelListener<LayoutSet>>();
1450    
1451                                    for (String listenerClassName : listenerClassNames) {
1452                                            listenersList.add((ModelListener<LayoutSet>)InstanceFactory.newInstance(
1453                                                            listenerClassName));
1454                                    }
1455    
1456                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1457                            }
1458                            catch (Exception e) {
1459                                    _log.error(e);
1460                            }
1461                    }
1462            }
1463    
1464            public void destroy() {
1465                    EntityCacheUtil.removeCache(LayoutSetImpl.class.getName());
1466                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1467                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
1468            }
1469    
1470            @BeanReference(type = AccountPersistence.class)
1471            protected AccountPersistence accountPersistence;
1472            @BeanReference(type = AddressPersistence.class)
1473            protected AddressPersistence addressPersistence;
1474            @BeanReference(type = BrowserTrackerPersistence.class)
1475            protected BrowserTrackerPersistence browserTrackerPersistence;
1476            @BeanReference(type = ClassNamePersistence.class)
1477            protected ClassNamePersistence classNamePersistence;
1478            @BeanReference(type = ClusterGroupPersistence.class)
1479            protected ClusterGroupPersistence clusterGroupPersistence;
1480            @BeanReference(type = CompanyPersistence.class)
1481            protected CompanyPersistence companyPersistence;
1482            @BeanReference(type = ContactPersistence.class)
1483            protected ContactPersistence contactPersistence;
1484            @BeanReference(type = CountryPersistence.class)
1485            protected CountryPersistence countryPersistence;
1486            @BeanReference(type = EmailAddressPersistence.class)
1487            protected EmailAddressPersistence emailAddressPersistence;
1488            @BeanReference(type = GroupPersistence.class)
1489            protected GroupPersistence groupPersistence;
1490            @BeanReference(type = ImagePersistence.class)
1491            protected ImagePersistence imagePersistence;
1492            @BeanReference(type = LayoutPersistence.class)
1493            protected LayoutPersistence layoutPersistence;
1494            @BeanReference(type = LayoutPrototypePersistence.class)
1495            protected LayoutPrototypePersistence layoutPrototypePersistence;
1496            @BeanReference(type = LayoutSetPersistence.class)
1497            protected LayoutSetPersistence layoutSetPersistence;
1498            @BeanReference(type = LayoutSetPrototypePersistence.class)
1499            protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
1500            @BeanReference(type = ListTypePersistence.class)
1501            protected ListTypePersistence listTypePersistence;
1502            @BeanReference(type = LockPersistence.class)
1503            protected LockPersistence lockPersistence;
1504            @BeanReference(type = MembershipRequestPersistence.class)
1505            protected MembershipRequestPersistence membershipRequestPersistence;
1506            @BeanReference(type = OrganizationPersistence.class)
1507            protected OrganizationPersistence organizationPersistence;
1508            @BeanReference(type = OrgGroupPermissionPersistence.class)
1509            protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1510            @BeanReference(type = OrgGroupRolePersistence.class)
1511            protected OrgGroupRolePersistence orgGroupRolePersistence;
1512            @BeanReference(type = OrgLaborPersistence.class)
1513            protected OrgLaborPersistence orgLaborPersistence;
1514            @BeanReference(type = PasswordPolicyPersistence.class)
1515            protected PasswordPolicyPersistence passwordPolicyPersistence;
1516            @BeanReference(type = PasswordPolicyRelPersistence.class)
1517            protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1518            @BeanReference(type = PasswordTrackerPersistence.class)
1519            protected PasswordTrackerPersistence passwordTrackerPersistence;
1520            @BeanReference(type = PermissionPersistence.class)
1521            protected PermissionPersistence permissionPersistence;
1522            @BeanReference(type = PhonePersistence.class)
1523            protected PhonePersistence phonePersistence;
1524            @BeanReference(type = PluginSettingPersistence.class)
1525            protected PluginSettingPersistence pluginSettingPersistence;
1526            @BeanReference(type = PortletPersistence.class)
1527            protected PortletPersistence portletPersistence;
1528            @BeanReference(type = PortletItemPersistence.class)
1529            protected PortletItemPersistence portletItemPersistence;
1530            @BeanReference(type = PortletPreferencesPersistence.class)
1531            protected PortletPreferencesPersistence portletPreferencesPersistence;
1532            @BeanReference(type = RegionPersistence.class)
1533            protected RegionPersistence regionPersistence;
1534            @BeanReference(type = ReleasePersistence.class)
1535            protected ReleasePersistence releasePersistence;
1536            @BeanReference(type = ResourcePersistence.class)
1537            protected ResourcePersistence resourcePersistence;
1538            @BeanReference(type = ResourceActionPersistence.class)
1539            protected ResourceActionPersistence resourceActionPersistence;
1540            @BeanReference(type = ResourceCodePersistence.class)
1541            protected ResourceCodePersistence resourceCodePersistence;
1542            @BeanReference(type = ResourcePermissionPersistence.class)
1543            protected ResourcePermissionPersistence resourcePermissionPersistence;
1544            @BeanReference(type = RolePersistence.class)
1545            protected RolePersistence rolePersistence;
1546            @BeanReference(type = ServiceComponentPersistence.class)
1547            protected ServiceComponentPersistence serviceComponentPersistence;
1548            @BeanReference(type = ShardPersistence.class)
1549            protected ShardPersistence shardPersistence;
1550            @BeanReference(type = SubscriptionPersistence.class)
1551            protected SubscriptionPersistence subscriptionPersistence;
1552            @BeanReference(type = TicketPersistence.class)
1553            protected TicketPersistence ticketPersistence;
1554            @BeanReference(type = TeamPersistence.class)
1555            protected TeamPersistence teamPersistence;
1556            @BeanReference(type = UserPersistence.class)
1557            protected UserPersistence userPersistence;
1558            @BeanReference(type = UserGroupPersistence.class)
1559            protected UserGroupPersistence userGroupPersistence;
1560            @BeanReference(type = UserGroupGroupRolePersistence.class)
1561            protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1562            @BeanReference(type = UserGroupRolePersistence.class)
1563            protected UserGroupRolePersistence userGroupRolePersistence;
1564            @BeanReference(type = UserIdMapperPersistence.class)
1565            protected UserIdMapperPersistence userIdMapperPersistence;
1566            @BeanReference(type = UserTrackerPersistence.class)
1567            protected UserTrackerPersistence userTrackerPersistence;
1568            @BeanReference(type = UserTrackerPathPersistence.class)
1569            protected UserTrackerPathPersistence userTrackerPathPersistence;
1570            @BeanReference(type = WebDAVPropsPersistence.class)
1571            protected WebDAVPropsPersistence webDAVPropsPersistence;
1572            @BeanReference(type = WebsitePersistence.class)
1573            protected WebsitePersistence websitePersistence;
1574            @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
1575            protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
1576            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
1577            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
1578            private static final String _SQL_SELECT_LAYOUTSET = "SELECT layoutSet FROM LayoutSet layoutSet";
1579            private static final String _SQL_SELECT_LAYOUTSET_WHERE = "SELECT layoutSet FROM LayoutSet layoutSet WHERE ";
1580            private static final String _SQL_COUNT_LAYOUTSET = "SELECT COUNT(layoutSet) FROM LayoutSet layoutSet";
1581            private static final String _SQL_COUNT_LAYOUTSET_WHERE = "SELECT COUNT(layoutSet) FROM LayoutSet layoutSet WHERE ";
1582            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "layoutSet.groupId = ?";
1583            private static final String _FINDER_COLUMN_VIRTUALHOST_VIRTUALHOST_1 = "layoutSet.virtualHost IS NULL";
1584            private static final String _FINDER_COLUMN_VIRTUALHOST_VIRTUALHOST_2 = "layoutSet.virtualHost = ?";
1585            private static final String _FINDER_COLUMN_VIRTUALHOST_VIRTUALHOST_3 = "(layoutSet.virtualHost IS NULL OR layoutSet.virtualHost = ?)";
1586            private static final String _FINDER_COLUMN_G_P_GROUPID_2 = "layoutSet.groupId = ? AND ";
1587            private static final String _FINDER_COLUMN_G_P_PRIVATELAYOUT_2 = "layoutSet.privateLayout = ?";
1588            private static final String _ORDER_BY_ENTITY_ALIAS = "layoutSet.";
1589            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No LayoutSet exists with the primary key ";
1590            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No LayoutSet exists with the key {";
1591            private static Log _log = LogFactoryUtil.getLog(LayoutSetPersistenceImpl.class);
1592    }