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