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            public LayoutSetPersistenceImpl() {
1362                    setModelClass(LayoutSet.class);
1363            }
1364    
1365            /**
1366             * Caches the layout set in the entity cache if it is enabled.
1367             *
1368             * @param layoutSet the layout set
1369             */
1370            @Override
1371            public void cacheResult(LayoutSet layoutSet) {
1372                    EntityCacheUtil.putResult(LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
1373                            LayoutSetImpl.class, layoutSet.getPrimaryKey(), layoutSet);
1374    
1375                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P,
1376                            new Object[] { layoutSet.getGroupId(), layoutSet.getPrivateLayout() },
1377                            layoutSet);
1378    
1379                    layoutSet.resetOriginalValues();
1380            }
1381    
1382            /**
1383             * Caches the layout sets in the entity cache if it is enabled.
1384             *
1385             * @param layoutSets the layout sets
1386             */
1387            @Override
1388            public void cacheResult(List<LayoutSet> layoutSets) {
1389                    for (LayoutSet layoutSet : layoutSets) {
1390                            if (EntityCacheUtil.getResult(
1391                                                    LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
1392                                                    LayoutSetImpl.class, layoutSet.getPrimaryKey()) == null) {
1393                                    cacheResult(layoutSet);
1394                            }
1395                            else {
1396                                    layoutSet.resetOriginalValues();
1397                            }
1398                    }
1399            }
1400    
1401            /**
1402             * Clears the cache for all layout sets.
1403             *
1404             * <p>
1405             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
1406             * </p>
1407             */
1408            @Override
1409            public void clearCache() {
1410                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
1411                            CacheRegistryUtil.clear(LayoutSetImpl.class.getName());
1412                    }
1413    
1414                    EntityCacheUtil.clearCache(LayoutSetImpl.class.getName());
1415    
1416                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
1417                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1418                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1419            }
1420    
1421            /**
1422             * Clears the cache for the layout set.
1423             *
1424             * <p>
1425             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
1426             * </p>
1427             */
1428            @Override
1429            public void clearCache(LayoutSet layoutSet) {
1430                    EntityCacheUtil.removeResult(LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
1431                            LayoutSetImpl.class, layoutSet.getPrimaryKey());
1432    
1433                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1434                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1435    
1436                    clearUniqueFindersCache(layoutSet);
1437            }
1438    
1439            @Override
1440            public void clearCache(List<LayoutSet> layoutSets) {
1441                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1442                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1443    
1444                    for (LayoutSet layoutSet : layoutSets) {
1445                            EntityCacheUtil.removeResult(LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
1446                                    LayoutSetImpl.class, layoutSet.getPrimaryKey());
1447    
1448                            clearUniqueFindersCache(layoutSet);
1449                    }
1450            }
1451    
1452            protected void cacheUniqueFindersCache(LayoutSet layoutSet) {
1453                    if (layoutSet.isNew()) {
1454                            Object[] args = new Object[] {
1455                                            layoutSet.getGroupId(), layoutSet.getPrivateLayout()
1456                                    };
1457    
1458                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_P, args,
1459                                    Long.valueOf(1));
1460                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P, args, layoutSet);
1461                    }
1462                    else {
1463                            LayoutSetModelImpl layoutSetModelImpl = (LayoutSetModelImpl)layoutSet;
1464    
1465                            if ((layoutSetModelImpl.getColumnBitmask() &
1466                                            FINDER_PATH_FETCH_BY_G_P.getColumnBitmask()) != 0) {
1467                                    Object[] args = new Object[] {
1468                                                    layoutSet.getGroupId(), layoutSet.getPrivateLayout()
1469                                            };
1470    
1471                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_P, args,
1472                                            Long.valueOf(1));
1473                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P, args,
1474                                            layoutSet);
1475                            }
1476                    }
1477            }
1478    
1479            protected void clearUniqueFindersCache(LayoutSet layoutSet) {
1480                    LayoutSetModelImpl layoutSetModelImpl = (LayoutSetModelImpl)layoutSet;
1481    
1482                    Object[] args = new Object[] {
1483                                    layoutSet.getGroupId(), layoutSet.getPrivateLayout()
1484                            };
1485    
1486                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P, args);
1487                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P, args);
1488    
1489                    if ((layoutSetModelImpl.getColumnBitmask() &
1490                                    FINDER_PATH_FETCH_BY_G_P.getColumnBitmask()) != 0) {
1491                            args = new Object[] {
1492                                            layoutSetModelImpl.getOriginalGroupId(),
1493                                            layoutSetModelImpl.getOriginalPrivateLayout()
1494                                    };
1495    
1496                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P, args);
1497                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P, args);
1498                    }
1499            }
1500    
1501            /**
1502             * Creates a new layout set with the primary key. Does not add the layout set to the database.
1503             *
1504             * @param layoutSetId the primary key for the new layout set
1505             * @return the new layout set
1506             */
1507            @Override
1508            public LayoutSet create(long layoutSetId) {
1509                    LayoutSet layoutSet = new LayoutSetImpl();
1510    
1511                    layoutSet.setNew(true);
1512                    layoutSet.setPrimaryKey(layoutSetId);
1513    
1514                    return layoutSet;
1515            }
1516    
1517            /**
1518             * Removes the layout set with the primary key from the database. Also notifies the appropriate model listeners.
1519             *
1520             * @param layoutSetId the primary key of the layout set
1521             * @return the layout set that was removed
1522             * @throws com.liferay.portal.NoSuchLayoutSetException if a layout set with the primary key could not be found
1523             * @throws SystemException if a system exception occurred
1524             */
1525            @Override
1526            public LayoutSet remove(long layoutSetId)
1527                    throws NoSuchLayoutSetException, SystemException {
1528                    return remove((Serializable)layoutSetId);
1529            }
1530    
1531            /**
1532             * Removes the layout set with the primary key from the database. Also notifies the appropriate model listeners.
1533             *
1534             * @param primaryKey the primary key of the layout set
1535             * @return the layout set that was removed
1536             * @throws com.liferay.portal.NoSuchLayoutSetException if a layout set with the primary key could not be found
1537             * @throws SystemException if a system exception occurred
1538             */
1539            @Override
1540            public LayoutSet remove(Serializable primaryKey)
1541                    throws NoSuchLayoutSetException, SystemException {
1542                    Session session = null;
1543    
1544                    try {
1545                            session = openSession();
1546    
1547                            LayoutSet layoutSet = (LayoutSet)session.get(LayoutSetImpl.class,
1548                                            primaryKey);
1549    
1550                            if (layoutSet == null) {
1551                                    if (_log.isWarnEnabled()) {
1552                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1553                                    }
1554    
1555                                    throw new NoSuchLayoutSetException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1556                                            primaryKey);
1557                            }
1558    
1559                            return remove(layoutSet);
1560                    }
1561                    catch (NoSuchLayoutSetException nsee) {
1562                            throw nsee;
1563                    }
1564                    catch (Exception e) {
1565                            throw processException(e);
1566                    }
1567                    finally {
1568                            closeSession(session);
1569                    }
1570            }
1571    
1572            @Override
1573            protected LayoutSet removeImpl(LayoutSet layoutSet)
1574                    throws SystemException {
1575                    layoutSet = toUnwrappedModel(layoutSet);
1576    
1577                    Session session = null;
1578    
1579                    try {
1580                            session = openSession();
1581    
1582                            if (!session.contains(layoutSet)) {
1583                                    layoutSet = (LayoutSet)session.get(LayoutSetImpl.class,
1584                                                    layoutSet.getPrimaryKeyObj());
1585                            }
1586    
1587                            if (layoutSet != null) {
1588                                    session.delete(layoutSet);
1589                            }
1590                    }
1591                    catch (Exception e) {
1592                            throw processException(e);
1593                    }
1594                    finally {
1595                            closeSession(session);
1596                    }
1597    
1598                    if (layoutSet != null) {
1599                            clearCache(layoutSet);
1600                    }
1601    
1602                    return layoutSet;
1603            }
1604    
1605            @Override
1606            public LayoutSet updateImpl(com.liferay.portal.model.LayoutSet layoutSet)
1607                    throws SystemException {
1608                    layoutSet = toUnwrappedModel(layoutSet);
1609    
1610                    boolean isNew = layoutSet.isNew();
1611    
1612                    LayoutSetModelImpl layoutSetModelImpl = (LayoutSetModelImpl)layoutSet;
1613    
1614                    Session session = null;
1615    
1616                    try {
1617                            session = openSession();
1618    
1619                            if (layoutSet.isNew()) {
1620                                    session.save(layoutSet);
1621    
1622                                    layoutSet.setNew(false);
1623                            }
1624                            else {
1625                                    session.merge(layoutSet);
1626                            }
1627                    }
1628                    catch (Exception e) {
1629                            throw processException(e);
1630                    }
1631                    finally {
1632                            closeSession(session);
1633                    }
1634    
1635                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1636    
1637                    if (isNew || !LayoutSetModelImpl.COLUMN_BITMASK_ENABLED) {
1638                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1639                    }
1640    
1641                    else {
1642                            if ((layoutSetModelImpl.getColumnBitmask() &
1643                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
1644                                    Object[] args = new Object[] {
1645                                                    layoutSetModelImpl.getOriginalGroupId()
1646                                            };
1647    
1648                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
1649                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
1650                                            args);
1651    
1652                                    args = new Object[] { layoutSetModelImpl.getGroupId() };
1653    
1654                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
1655                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
1656                                            args);
1657                            }
1658    
1659                            if ((layoutSetModelImpl.getColumnBitmask() &
1660                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LAYOUTSETPROTOTYPEUUID.getColumnBitmask()) != 0) {
1661                                    Object[] args = new Object[] {
1662                                                    layoutSetModelImpl.getOriginalLayoutSetPrototypeUuid()
1663                                            };
1664    
1665                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_LAYOUTSETPROTOTYPEUUID,
1666                                            args);
1667                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LAYOUTSETPROTOTYPEUUID,
1668                                            args);
1669    
1670                                    args = new Object[] {
1671                                                    layoutSetModelImpl.getLayoutSetPrototypeUuid()
1672                                            };
1673    
1674                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_LAYOUTSETPROTOTYPEUUID,
1675                                            args);
1676                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LAYOUTSETPROTOTYPEUUID,
1677                                            args);
1678                            }
1679                    }
1680    
1681                    EntityCacheUtil.putResult(LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
1682                            LayoutSetImpl.class, layoutSet.getPrimaryKey(), layoutSet);
1683    
1684                    clearUniqueFindersCache(layoutSet);
1685                    cacheUniqueFindersCache(layoutSet);
1686    
1687                    return layoutSet;
1688            }
1689    
1690            protected LayoutSet toUnwrappedModel(LayoutSet layoutSet) {
1691                    if (layoutSet instanceof LayoutSetImpl) {
1692                            return layoutSet;
1693                    }
1694    
1695                    LayoutSetImpl layoutSetImpl = new LayoutSetImpl();
1696    
1697                    layoutSetImpl.setNew(layoutSet.isNew());
1698                    layoutSetImpl.setPrimaryKey(layoutSet.getPrimaryKey());
1699    
1700                    layoutSetImpl.setLayoutSetId(layoutSet.getLayoutSetId());
1701                    layoutSetImpl.setGroupId(layoutSet.getGroupId());
1702                    layoutSetImpl.setCompanyId(layoutSet.getCompanyId());
1703                    layoutSetImpl.setCreateDate(layoutSet.getCreateDate());
1704                    layoutSetImpl.setModifiedDate(layoutSet.getModifiedDate());
1705                    layoutSetImpl.setPrivateLayout(layoutSet.isPrivateLayout());
1706                    layoutSetImpl.setLogo(layoutSet.isLogo());
1707                    layoutSetImpl.setLogoId(layoutSet.getLogoId());
1708                    layoutSetImpl.setThemeId(layoutSet.getThemeId());
1709                    layoutSetImpl.setColorSchemeId(layoutSet.getColorSchemeId());
1710                    layoutSetImpl.setWapThemeId(layoutSet.getWapThemeId());
1711                    layoutSetImpl.setWapColorSchemeId(layoutSet.getWapColorSchemeId());
1712                    layoutSetImpl.setCss(layoutSet.getCss());
1713                    layoutSetImpl.setPageCount(layoutSet.getPageCount());
1714                    layoutSetImpl.setSettings(layoutSet.getSettings());
1715                    layoutSetImpl.setLayoutSetPrototypeUuid(layoutSet.getLayoutSetPrototypeUuid());
1716                    layoutSetImpl.setLayoutSetPrototypeLinkEnabled(layoutSet.isLayoutSetPrototypeLinkEnabled());
1717    
1718                    return layoutSetImpl;
1719            }
1720    
1721            /**
1722             * Returns the layout set with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
1723             *
1724             * @param primaryKey the primary key of the layout set
1725             * @return the layout set
1726             * @throws com.liferay.portal.NoSuchLayoutSetException if a layout set with the primary key could not be found
1727             * @throws SystemException if a system exception occurred
1728             */
1729            @Override
1730            public LayoutSet findByPrimaryKey(Serializable primaryKey)
1731                    throws NoSuchLayoutSetException, SystemException {
1732                    LayoutSet layoutSet = fetchByPrimaryKey(primaryKey);
1733    
1734                    if (layoutSet == null) {
1735                            if (_log.isWarnEnabled()) {
1736                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1737                            }
1738    
1739                            throw new NoSuchLayoutSetException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1740                                    primaryKey);
1741                    }
1742    
1743                    return layoutSet;
1744            }
1745    
1746            /**
1747             * Returns the layout set with the primary key or throws a {@link com.liferay.portal.NoSuchLayoutSetException} if it could not be found.
1748             *
1749             * @param layoutSetId the primary key of the layout set
1750             * @return the layout set
1751             * @throws com.liferay.portal.NoSuchLayoutSetException if a layout set with the primary key could not be found
1752             * @throws SystemException if a system exception occurred
1753             */
1754            @Override
1755            public LayoutSet findByPrimaryKey(long layoutSetId)
1756                    throws NoSuchLayoutSetException, SystemException {
1757                    return findByPrimaryKey((Serializable)layoutSetId);
1758            }
1759    
1760            /**
1761             * Returns the layout set with the primary key or returns <code>null</code> if it could not be found.
1762             *
1763             * @param primaryKey the primary key of the layout set
1764             * @return the layout set, or <code>null</code> if a layout set with the primary key could not be found
1765             * @throws SystemException if a system exception occurred
1766             */
1767            @Override
1768            public LayoutSet fetchByPrimaryKey(Serializable primaryKey)
1769                    throws SystemException {
1770                    LayoutSet layoutSet = (LayoutSet)EntityCacheUtil.getResult(LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
1771                                    LayoutSetImpl.class, primaryKey);
1772    
1773                    if (layoutSet == _nullLayoutSet) {
1774                            return null;
1775                    }
1776    
1777                    if (layoutSet == null) {
1778                            Session session = null;
1779    
1780                            try {
1781                                    session = openSession();
1782    
1783                                    layoutSet = (LayoutSet)session.get(LayoutSetImpl.class,
1784                                                    primaryKey);
1785    
1786                                    if (layoutSet != null) {
1787                                            cacheResult(layoutSet);
1788                                    }
1789                                    else {
1790                                            EntityCacheUtil.putResult(LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
1791                                                    LayoutSetImpl.class, primaryKey, _nullLayoutSet);
1792                                    }
1793                            }
1794                            catch (Exception e) {
1795                                    EntityCacheUtil.removeResult(LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
1796                                            LayoutSetImpl.class, primaryKey);
1797    
1798                                    throw processException(e);
1799                            }
1800                            finally {
1801                                    closeSession(session);
1802                            }
1803                    }
1804    
1805                    return layoutSet;
1806            }
1807    
1808            /**
1809             * Returns the layout set with the primary key or returns <code>null</code> if it could not be found.
1810             *
1811             * @param layoutSetId the primary key of the layout set
1812             * @return the layout set, or <code>null</code> if a layout set with the primary key could not be found
1813             * @throws SystemException if a system exception occurred
1814             */
1815            @Override
1816            public LayoutSet fetchByPrimaryKey(long layoutSetId)
1817                    throws SystemException {
1818                    return fetchByPrimaryKey((Serializable)layoutSetId);
1819            }
1820    
1821            /**
1822             * Returns all the layout sets.
1823             *
1824             * @return the layout sets
1825             * @throws SystemException if a system exception occurred
1826             */
1827            @Override
1828            public List<LayoutSet> findAll() throws SystemException {
1829                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1830            }
1831    
1832            /**
1833             * Returns a range of all the layout sets.
1834             *
1835             * <p>
1836             * 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.
1837             * </p>
1838             *
1839             * @param start the lower bound of the range of layout sets
1840             * @param end the upper bound of the range of layout sets (not inclusive)
1841             * @return the range of layout sets
1842             * @throws SystemException if a system exception occurred
1843             */
1844            @Override
1845            public List<LayoutSet> findAll(int start, int end)
1846                    throws SystemException {
1847                    return findAll(start, end, null);
1848            }
1849    
1850            /**
1851             * Returns an ordered range of all the layout sets.
1852             *
1853             * <p>
1854             * 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.
1855             * </p>
1856             *
1857             * @param start the lower bound of the range of layout sets
1858             * @param end the upper bound of the range of layout sets (not inclusive)
1859             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1860             * @return the ordered range of layout sets
1861             * @throws SystemException if a system exception occurred
1862             */
1863            @Override
1864            public List<LayoutSet> findAll(int start, int end,
1865                    OrderByComparator orderByComparator) throws SystemException {
1866                    boolean pagination = true;
1867                    FinderPath finderPath = null;
1868                    Object[] finderArgs = null;
1869    
1870                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1871                                    (orderByComparator == null)) {
1872                            pagination = false;
1873                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1874                            finderArgs = FINDER_ARGS_EMPTY;
1875                    }
1876                    else {
1877                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1878                            finderArgs = new Object[] { start, end, orderByComparator };
1879                    }
1880    
1881                    List<LayoutSet> list = (List<LayoutSet>)FinderCacheUtil.getResult(finderPath,
1882                                    finderArgs, this);
1883    
1884                    if (list == null) {
1885                            StringBundler query = null;
1886                            String sql = null;
1887    
1888                            if (orderByComparator != null) {
1889                                    query = new StringBundler(2 +
1890                                                    (orderByComparator.getOrderByFields().length * 3));
1891    
1892                                    query.append(_SQL_SELECT_LAYOUTSET);
1893    
1894                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1895                                            orderByComparator);
1896    
1897                                    sql = query.toString();
1898                            }
1899                            else {
1900                                    sql = _SQL_SELECT_LAYOUTSET;
1901    
1902                                    if (pagination) {
1903                                            sql = sql.concat(LayoutSetModelImpl.ORDER_BY_JPQL);
1904                                    }
1905                            }
1906    
1907                            Session session = null;
1908    
1909                            try {
1910                                    session = openSession();
1911    
1912                                    Query q = session.createQuery(sql);
1913    
1914                                    if (!pagination) {
1915                                            list = (List<LayoutSet>)QueryUtil.list(q, getDialect(),
1916                                                            start, end, false);
1917    
1918                                            Collections.sort(list);
1919    
1920                                            list = new UnmodifiableList<LayoutSet>(list);
1921                                    }
1922                                    else {
1923                                            list = (List<LayoutSet>)QueryUtil.list(q, getDialect(),
1924                                                            start, end);
1925                                    }
1926    
1927                                    cacheResult(list);
1928    
1929                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1930                            }
1931                            catch (Exception e) {
1932                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1933    
1934                                    throw processException(e);
1935                            }
1936                            finally {
1937                                    closeSession(session);
1938                            }
1939                    }
1940    
1941                    return list;
1942            }
1943    
1944            /**
1945             * Removes all the layout sets from the database.
1946             *
1947             * @throws SystemException if a system exception occurred
1948             */
1949            @Override
1950            public void removeAll() throws SystemException {
1951                    for (LayoutSet layoutSet : findAll()) {
1952                            remove(layoutSet);
1953                    }
1954            }
1955    
1956            /**
1957             * Returns the number of layout sets.
1958             *
1959             * @return the number of layout sets
1960             * @throws SystemException if a system exception occurred
1961             */
1962            @Override
1963            public int countAll() throws SystemException {
1964                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1965                                    FINDER_ARGS_EMPTY, this);
1966    
1967                    if (count == null) {
1968                            Session session = null;
1969    
1970                            try {
1971                                    session = openSession();
1972    
1973                                    Query q = session.createQuery(_SQL_COUNT_LAYOUTSET);
1974    
1975                                    count = (Long)q.uniqueResult();
1976    
1977                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1978                                            FINDER_ARGS_EMPTY, count);
1979                            }
1980                            catch (Exception e) {
1981                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
1982                                            FINDER_ARGS_EMPTY);
1983    
1984                                    throw processException(e);
1985                            }
1986                            finally {
1987                                    closeSession(session);
1988                            }
1989                    }
1990    
1991                    return count.intValue();
1992            }
1993    
1994            @Override
1995            protected Set<String> getBadColumnNames() {
1996                    return _badColumnNames;
1997            }
1998    
1999            /**
2000             * Initializes the layout set persistence.
2001             */
2002            public void afterPropertiesSet() {
2003                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2004                                            com.liferay.portal.util.PropsUtil.get(
2005                                                    "value.object.listener.com.liferay.portal.model.LayoutSet")));
2006    
2007                    if (listenerClassNames.length > 0) {
2008                            try {
2009                                    List<ModelListener<LayoutSet>> listenersList = new ArrayList<ModelListener<LayoutSet>>();
2010    
2011                                    for (String listenerClassName : listenerClassNames) {
2012                                            listenersList.add((ModelListener<LayoutSet>)InstanceFactory.newInstance(
2013                                                            getClassLoader(), listenerClassName));
2014                                    }
2015    
2016                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2017                            }
2018                            catch (Exception e) {
2019                                    _log.error(e);
2020                            }
2021                    }
2022            }
2023    
2024            public void destroy() {
2025                    EntityCacheUtil.removeCache(LayoutSetImpl.class.getName());
2026                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2027                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2028                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2029            }
2030    
2031            private static final String _SQL_SELECT_LAYOUTSET = "SELECT layoutSet FROM LayoutSet layoutSet";
2032            private static final String _SQL_SELECT_LAYOUTSET_WHERE = "SELECT layoutSet FROM LayoutSet layoutSet WHERE ";
2033            private static final String _SQL_COUNT_LAYOUTSET = "SELECT COUNT(layoutSet) FROM LayoutSet layoutSet";
2034            private static final String _SQL_COUNT_LAYOUTSET_WHERE = "SELECT COUNT(layoutSet) FROM LayoutSet layoutSet WHERE ";
2035            private static final String _ORDER_BY_ENTITY_ALIAS = "layoutSet.";
2036            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No LayoutSet exists with the primary key ";
2037            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No LayoutSet exists with the key {";
2038            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2039            private static Log _log = LogFactoryUtil.getLog(LayoutSetPersistenceImpl.class);
2040            private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
2041                                    "settings"
2042                            });
2043            private static LayoutSet _nullLayoutSet = new LayoutSetImpl() {
2044                            @Override
2045                            public Object clone() {
2046                                    return this;
2047                            }
2048    
2049                            @Override
2050                            public CacheModel<LayoutSet> toCacheModel() {
2051                                    return _nullLayoutSetCacheModel;
2052                            }
2053                    };
2054    
2055            private static CacheModel<LayoutSet> _nullLayoutSetCacheModel = new CacheModel<LayoutSet>() {
2056                            @Override
2057                            public LayoutSet toEntityModel() {
2058                                    return _nullLayoutSet;
2059                            }
2060                    };
2061    }