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