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