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.SQLQuery;
029    import com.liferay.portal.kernel.dao.orm.Session;
030    import com.liferay.portal.kernel.exception.NoSuchLayoutSetBranchException;
031    import com.liferay.portal.kernel.log.Log;
032    import com.liferay.portal.kernel.log.LogFactoryUtil;
033    import com.liferay.portal.kernel.model.CacheModel;
034    import com.liferay.portal.kernel.model.LayoutSetBranch;
035    import com.liferay.portal.kernel.model.MVCCModel;
036    import com.liferay.portal.kernel.security.permission.InlineSQLHelperUtil;
037    import com.liferay.portal.kernel.service.ServiceContext;
038    import com.liferay.portal.kernel.service.ServiceContextThreadLocal;
039    import com.liferay.portal.kernel.service.persistence.CompanyProvider;
040    import com.liferay.portal.kernel.service.persistence.CompanyProviderWrapper;
041    import com.liferay.portal.kernel.service.persistence.LayoutSetBranchPersistence;
042    import com.liferay.portal.kernel.service.persistence.impl.BasePersistenceImpl;
043    import com.liferay.portal.kernel.util.OrderByComparator;
044    import com.liferay.portal.kernel.util.SetUtil;
045    import com.liferay.portal.kernel.util.StringBundler;
046    import com.liferay.portal.kernel.util.StringPool;
047    import com.liferay.portal.kernel.util.Validator;
048    import com.liferay.portal.model.impl.LayoutSetBranchImpl;
049    import com.liferay.portal.model.impl.LayoutSetBranchModelImpl;
050    
051    import java.io.Serializable;
052    
053    import java.util.Collections;
054    import java.util.Date;
055    import java.util.HashMap;
056    import java.util.HashSet;
057    import java.util.Iterator;
058    import java.util.List;
059    import java.util.Map;
060    import java.util.Set;
061    
062    /**
063     * The persistence implementation for the layout set branch service.
064     *
065     * <p>
066     * Caching information and settings can be found in <code>portal.properties</code>
067     * </p>
068     *
069     * @author Brian Wing Shun Chan
070     * @see LayoutSetBranchPersistence
071     * @see com.liferay.portal.kernel.service.persistence.LayoutSetBranchUtil
072     * @generated
073     */
074    @ProviderType
075    public class LayoutSetBranchPersistenceImpl extends BasePersistenceImpl<LayoutSetBranch>
076            implements LayoutSetBranchPersistence {
077            /*
078             * NOTE FOR DEVELOPERS:
079             *
080             * Never modify or reference this class directly. Always use {@link LayoutSetBranchUtil} to access the layout set branch persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
081             */
082            public static final String FINDER_CLASS_NAME_ENTITY = LayoutSetBranchImpl.class.getName();
083            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
084                    ".List1";
085            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
086                    ".List2";
087            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(LayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
088                            LayoutSetBranchModelImpl.FINDER_CACHE_ENABLED,
089                            LayoutSetBranchImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
090                            "findAll", new String[0]);
091            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(LayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
092                            LayoutSetBranchModelImpl.FINDER_CACHE_ENABLED,
093                            LayoutSetBranchImpl.class,
094                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
095            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(LayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
096                            LayoutSetBranchModelImpl.FINDER_CACHE_ENABLED, Long.class,
097                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
098            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(LayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
099                            LayoutSetBranchModelImpl.FINDER_CACHE_ENABLED,
100                            LayoutSetBranchImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
101                            "findByGroupId",
102                            new String[] {
103                                    Long.class.getName(),
104                                    
105                            Integer.class.getName(), Integer.class.getName(),
106                                    OrderByComparator.class.getName()
107                            });
108            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
109                    new FinderPath(LayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
110                            LayoutSetBranchModelImpl.FINDER_CACHE_ENABLED,
111                            LayoutSetBranchImpl.class,
112                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
113                            new String[] { Long.class.getName() },
114                            LayoutSetBranchModelImpl.GROUPID_COLUMN_BITMASK |
115                            LayoutSetBranchModelImpl.NAME_COLUMN_BITMASK);
116            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(LayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
117                            LayoutSetBranchModelImpl.FINDER_CACHE_ENABLED, Long.class,
118                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
119                            new String[] { Long.class.getName() });
120    
121            /**
122             * Returns all the layout set branchs where groupId = &#63;.
123             *
124             * @param groupId the group ID
125             * @return the matching layout set branchs
126             */
127            @Override
128            public List<LayoutSetBranch> findByGroupId(long groupId) {
129                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
130            }
131    
132            /**
133             * Returns a range of all the layout set branchs where groupId = &#63;.
134             *
135             * <p>
136             * 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 LayoutSetBranchModelImpl}. 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.
137             * </p>
138             *
139             * @param groupId the group ID
140             * @param start the lower bound of the range of layout set branchs
141             * @param end the upper bound of the range of layout set branchs (not inclusive)
142             * @return the range of matching layout set branchs
143             */
144            @Override
145            public List<LayoutSetBranch> findByGroupId(long groupId, int start, int end) {
146                    return findByGroupId(groupId, start, end, null);
147            }
148    
149            /**
150             * Returns an ordered range of all the layout set branchs where groupId = &#63;.
151             *
152             * <p>
153             * 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 LayoutSetBranchModelImpl}. 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.
154             * </p>
155             *
156             * @param groupId the group ID
157             * @param start the lower bound of the range of layout set branchs
158             * @param end the upper bound of the range of layout set branchs (not inclusive)
159             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
160             * @return the ordered range of matching layout set branchs
161             */
162            @Override
163            public List<LayoutSetBranch> findByGroupId(long groupId, int start,
164                    int end, OrderByComparator<LayoutSetBranch> orderByComparator) {
165                    return findByGroupId(groupId, start, end, orderByComparator, true);
166            }
167    
168            /**
169             * Returns an ordered range of all the layout set branchs where groupId = &#63;.
170             *
171             * <p>
172             * 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 LayoutSetBranchModelImpl}. 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.
173             * </p>
174             *
175             * @param groupId the group ID
176             * @param start the lower bound of the range of layout set branchs
177             * @param end the upper bound of the range of layout set branchs (not inclusive)
178             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
179             * @param retrieveFromCache whether to retrieve from the finder cache
180             * @return the ordered range of matching layout set branchs
181             */
182            @Override
183            public List<LayoutSetBranch> findByGroupId(long groupId, int start,
184                    int end, OrderByComparator<LayoutSetBranch> orderByComparator,
185                    boolean retrieveFromCache) {
186                    boolean pagination = true;
187                    FinderPath finderPath = null;
188                    Object[] finderArgs = null;
189    
190                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
191                                    (orderByComparator == null)) {
192                            pagination = false;
193                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
194                            finderArgs = new Object[] { groupId };
195                    }
196                    else {
197                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
198                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
199                    }
200    
201                    List<LayoutSetBranch> list = null;
202    
203                    if (retrieveFromCache) {
204                            list = (List<LayoutSetBranch>)finderCache.getResult(finderPath,
205                                            finderArgs, this);
206    
207                            if ((list != null) && !list.isEmpty()) {
208                                    for (LayoutSetBranch layoutSetBranch : list) {
209                                            if ((groupId != layoutSetBranch.getGroupId())) {
210                                                    list = null;
211    
212                                                    break;
213                                            }
214                                    }
215                            }
216                    }
217    
218                    if (list == null) {
219                            StringBundler query = null;
220    
221                            if (orderByComparator != null) {
222                                    query = new StringBundler(3 +
223                                                    (orderByComparator.getOrderByFields().length * 2));
224                            }
225                            else {
226                                    query = new StringBundler(3);
227                            }
228    
229                            query.append(_SQL_SELECT_LAYOUTSETBRANCH_WHERE);
230    
231                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
232    
233                            if (orderByComparator != null) {
234                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
235                                            orderByComparator);
236                            }
237                            else
238                             if (pagination) {
239                                    query.append(LayoutSetBranchModelImpl.ORDER_BY_JPQL);
240                            }
241    
242                            String sql = query.toString();
243    
244                            Session session = null;
245    
246                            try {
247                                    session = openSession();
248    
249                                    Query q = session.createQuery(sql);
250    
251                                    QueryPos qPos = QueryPos.getInstance(q);
252    
253                                    qPos.add(groupId);
254    
255                                    if (!pagination) {
256                                            list = (List<LayoutSetBranch>)QueryUtil.list(q,
257                                                            getDialect(), start, end, false);
258    
259                                            Collections.sort(list);
260    
261                                            list = Collections.unmodifiableList(list);
262                                    }
263                                    else {
264                                            list = (List<LayoutSetBranch>)QueryUtil.list(q,
265                                                            getDialect(), start, end);
266                                    }
267    
268                                    cacheResult(list);
269    
270                                    finderCache.putResult(finderPath, finderArgs, list);
271                            }
272                            catch (Exception e) {
273                                    finderCache.removeResult(finderPath, finderArgs);
274    
275                                    throw processException(e);
276                            }
277                            finally {
278                                    closeSession(session);
279                            }
280                    }
281    
282                    return list;
283            }
284    
285            /**
286             * Returns the first layout set branch in the ordered set where groupId = &#63;.
287             *
288             * @param groupId the group ID
289             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
290             * @return the first matching layout set branch
291             * @throws NoSuchLayoutSetBranchException if a matching layout set branch could not be found
292             */
293            @Override
294            public LayoutSetBranch findByGroupId_First(long groupId,
295                    OrderByComparator<LayoutSetBranch> orderByComparator)
296                    throws NoSuchLayoutSetBranchException {
297                    LayoutSetBranch layoutSetBranch = fetchByGroupId_First(groupId,
298                                    orderByComparator);
299    
300                    if (layoutSetBranch != null) {
301                            return layoutSetBranch;
302                    }
303    
304                    StringBundler msg = new StringBundler(4);
305    
306                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
307    
308                    msg.append("groupId=");
309                    msg.append(groupId);
310    
311                    msg.append(StringPool.CLOSE_CURLY_BRACE);
312    
313                    throw new NoSuchLayoutSetBranchException(msg.toString());
314            }
315    
316            /**
317             * Returns the first layout set branch in the ordered set where groupId = &#63;.
318             *
319             * @param groupId the group ID
320             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
321             * @return the first matching layout set branch, or <code>null</code> if a matching layout set branch could not be found
322             */
323            @Override
324            public LayoutSetBranch fetchByGroupId_First(long groupId,
325                    OrderByComparator<LayoutSetBranch> orderByComparator) {
326                    List<LayoutSetBranch> list = findByGroupId(groupId, 0, 1,
327                                    orderByComparator);
328    
329                    if (!list.isEmpty()) {
330                            return list.get(0);
331                    }
332    
333                    return null;
334            }
335    
336            /**
337             * Returns the last layout set branch in the ordered set where groupId = &#63;.
338             *
339             * @param groupId the group ID
340             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
341             * @return the last matching layout set branch
342             * @throws NoSuchLayoutSetBranchException if a matching layout set branch could not be found
343             */
344            @Override
345            public LayoutSetBranch findByGroupId_Last(long groupId,
346                    OrderByComparator<LayoutSetBranch> orderByComparator)
347                    throws NoSuchLayoutSetBranchException {
348                    LayoutSetBranch layoutSetBranch = fetchByGroupId_Last(groupId,
349                                    orderByComparator);
350    
351                    if (layoutSetBranch != null) {
352                            return layoutSetBranch;
353                    }
354    
355                    StringBundler msg = new StringBundler(4);
356    
357                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
358    
359                    msg.append("groupId=");
360                    msg.append(groupId);
361    
362                    msg.append(StringPool.CLOSE_CURLY_BRACE);
363    
364                    throw new NoSuchLayoutSetBranchException(msg.toString());
365            }
366    
367            /**
368             * Returns the last layout set branch in the ordered set where groupId = &#63;.
369             *
370             * @param groupId the group ID
371             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
372             * @return the last matching layout set branch, or <code>null</code> if a matching layout set branch could not be found
373             */
374            @Override
375            public LayoutSetBranch fetchByGroupId_Last(long groupId,
376                    OrderByComparator<LayoutSetBranch> orderByComparator) {
377                    int count = countByGroupId(groupId);
378    
379                    if (count == 0) {
380                            return null;
381                    }
382    
383                    List<LayoutSetBranch> list = findByGroupId(groupId, count - 1, count,
384                                    orderByComparator);
385    
386                    if (!list.isEmpty()) {
387                            return list.get(0);
388                    }
389    
390                    return null;
391            }
392    
393            /**
394             * Returns the layout set branchs before and after the current layout set branch in the ordered set where groupId = &#63;.
395             *
396             * @param layoutSetBranchId the primary key of the current layout set branch
397             * @param groupId the group ID
398             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
399             * @return the previous, current, and next layout set branch
400             * @throws NoSuchLayoutSetBranchException if a layout set branch with the primary key could not be found
401             */
402            @Override
403            public LayoutSetBranch[] findByGroupId_PrevAndNext(long layoutSetBranchId,
404                    long groupId, OrderByComparator<LayoutSetBranch> orderByComparator)
405                    throws NoSuchLayoutSetBranchException {
406                    LayoutSetBranch layoutSetBranch = findByPrimaryKey(layoutSetBranchId);
407    
408                    Session session = null;
409    
410                    try {
411                            session = openSession();
412    
413                            LayoutSetBranch[] array = new LayoutSetBranchImpl[3];
414    
415                            array[0] = getByGroupId_PrevAndNext(session, layoutSetBranch,
416                                            groupId, orderByComparator, true);
417    
418                            array[1] = layoutSetBranch;
419    
420                            array[2] = getByGroupId_PrevAndNext(session, layoutSetBranch,
421                                            groupId, orderByComparator, false);
422    
423                            return array;
424                    }
425                    catch (Exception e) {
426                            throw processException(e);
427                    }
428                    finally {
429                            closeSession(session);
430                    }
431            }
432    
433            protected LayoutSetBranch getByGroupId_PrevAndNext(Session session,
434                    LayoutSetBranch layoutSetBranch, long groupId,
435                    OrderByComparator<LayoutSetBranch> orderByComparator, boolean previous) {
436                    StringBundler query = null;
437    
438                    if (orderByComparator != null) {
439                            query = new StringBundler(4 +
440                                            (orderByComparator.getOrderByConditionFields().length * 3) +
441                                            (orderByComparator.getOrderByFields().length * 3));
442                    }
443                    else {
444                            query = new StringBundler(3);
445                    }
446    
447                    query.append(_SQL_SELECT_LAYOUTSETBRANCH_WHERE);
448    
449                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
450    
451                    if (orderByComparator != null) {
452                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
453    
454                            if (orderByConditionFields.length > 0) {
455                                    query.append(WHERE_AND);
456                            }
457    
458                            for (int i = 0; i < orderByConditionFields.length; i++) {
459                                    query.append(_ORDER_BY_ENTITY_ALIAS);
460                                    query.append(orderByConditionFields[i]);
461    
462                                    if ((i + 1) < orderByConditionFields.length) {
463                                            if (orderByComparator.isAscending() ^ previous) {
464                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
465                                            }
466                                            else {
467                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
468                                            }
469                                    }
470                                    else {
471                                            if (orderByComparator.isAscending() ^ previous) {
472                                                    query.append(WHERE_GREATER_THAN);
473                                            }
474                                            else {
475                                                    query.append(WHERE_LESSER_THAN);
476                                            }
477                                    }
478                            }
479    
480                            query.append(ORDER_BY_CLAUSE);
481    
482                            String[] orderByFields = orderByComparator.getOrderByFields();
483    
484                            for (int i = 0; i < orderByFields.length; i++) {
485                                    query.append(_ORDER_BY_ENTITY_ALIAS);
486                                    query.append(orderByFields[i]);
487    
488                                    if ((i + 1) < orderByFields.length) {
489                                            if (orderByComparator.isAscending() ^ previous) {
490                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
491                                            }
492                                            else {
493                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
494                                            }
495                                    }
496                                    else {
497                                            if (orderByComparator.isAscending() ^ previous) {
498                                                    query.append(ORDER_BY_ASC);
499                                            }
500                                            else {
501                                                    query.append(ORDER_BY_DESC);
502                                            }
503                                    }
504                            }
505                    }
506                    else {
507                            query.append(LayoutSetBranchModelImpl.ORDER_BY_JPQL);
508                    }
509    
510                    String sql = query.toString();
511    
512                    Query q = session.createQuery(sql);
513    
514                    q.setFirstResult(0);
515                    q.setMaxResults(2);
516    
517                    QueryPos qPos = QueryPos.getInstance(q);
518    
519                    qPos.add(groupId);
520    
521                    if (orderByComparator != null) {
522                            Object[] values = orderByComparator.getOrderByConditionValues(layoutSetBranch);
523    
524                            for (Object value : values) {
525                                    qPos.add(value);
526                            }
527                    }
528    
529                    List<LayoutSetBranch> list = q.list();
530    
531                    if (list.size() == 2) {
532                            return list.get(1);
533                    }
534                    else {
535                            return null;
536                    }
537            }
538    
539            /**
540             * Returns all the layout set branchs that the user has permission to view where groupId = &#63;.
541             *
542             * @param groupId the group ID
543             * @return the matching layout set branchs that the user has permission to view
544             */
545            @Override
546            public List<LayoutSetBranch> filterFindByGroupId(long groupId) {
547                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
548                            QueryUtil.ALL_POS, null);
549            }
550    
551            /**
552             * Returns a range of all the layout set branchs that the user has permission to view where groupId = &#63;.
553             *
554             * <p>
555             * 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 LayoutSetBranchModelImpl}. 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.
556             * </p>
557             *
558             * @param groupId the group ID
559             * @param start the lower bound of the range of layout set branchs
560             * @param end the upper bound of the range of layout set branchs (not inclusive)
561             * @return the range of matching layout set branchs that the user has permission to view
562             */
563            @Override
564            public List<LayoutSetBranch> filterFindByGroupId(long groupId, int start,
565                    int end) {
566                    return filterFindByGroupId(groupId, start, end, null);
567            }
568    
569            /**
570             * Returns an ordered range of all the layout set branchs that the user has permissions to view where groupId = &#63;.
571             *
572             * <p>
573             * 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 LayoutSetBranchModelImpl}. 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.
574             * </p>
575             *
576             * @param groupId the group ID
577             * @param start the lower bound of the range of layout set branchs
578             * @param end the upper bound of the range of layout set branchs (not inclusive)
579             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
580             * @return the ordered range of matching layout set branchs that the user has permission to view
581             */
582            @Override
583            public List<LayoutSetBranch> filterFindByGroupId(long groupId, int start,
584                    int end, OrderByComparator<LayoutSetBranch> orderByComparator) {
585                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
586                            return findByGroupId(groupId, start, end, orderByComparator);
587                    }
588    
589                    StringBundler query = null;
590    
591                    if (orderByComparator != null) {
592                            query = new StringBundler(3 +
593                                            (orderByComparator.getOrderByFields().length * 2));
594                    }
595                    else {
596                            query = new StringBundler(4);
597                    }
598    
599                    if (getDB().isSupportsInlineDistinct()) {
600                            query.append(_FILTER_SQL_SELECT_LAYOUTSETBRANCH_WHERE);
601                    }
602                    else {
603                            query.append(_FILTER_SQL_SELECT_LAYOUTSETBRANCH_NO_INLINE_DISTINCT_WHERE_1);
604                    }
605    
606                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
607    
608                    if (!getDB().isSupportsInlineDistinct()) {
609                            query.append(_FILTER_SQL_SELECT_LAYOUTSETBRANCH_NO_INLINE_DISTINCT_WHERE_2);
610                    }
611    
612                    if (orderByComparator != null) {
613                            if (getDB().isSupportsInlineDistinct()) {
614                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
615                                            orderByComparator, true);
616                            }
617                            else {
618                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
619                                            orderByComparator, true);
620                            }
621                    }
622                    else {
623                            if (getDB().isSupportsInlineDistinct()) {
624                                    query.append(LayoutSetBranchModelImpl.ORDER_BY_JPQL);
625                            }
626                            else {
627                                    query.append(LayoutSetBranchModelImpl.ORDER_BY_SQL);
628                            }
629                    }
630    
631                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
632                                    LayoutSetBranch.class.getName(),
633                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
634    
635                    Session session = null;
636    
637                    try {
638                            session = openSession();
639    
640                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
641    
642                            if (getDB().isSupportsInlineDistinct()) {
643                                    q.addEntity(_FILTER_ENTITY_ALIAS, LayoutSetBranchImpl.class);
644                            }
645                            else {
646                                    q.addEntity(_FILTER_ENTITY_TABLE, LayoutSetBranchImpl.class);
647                            }
648    
649                            QueryPos qPos = QueryPos.getInstance(q);
650    
651                            qPos.add(groupId);
652    
653                            return (List<LayoutSetBranch>)QueryUtil.list(q, getDialect(),
654                                    start, end);
655                    }
656                    catch (Exception e) {
657                            throw processException(e);
658                    }
659                    finally {
660                            closeSession(session);
661                    }
662            }
663    
664            /**
665             * Returns the layout set branchs before and after the current layout set branch in the ordered set of layout set branchs that the user has permission to view where groupId = &#63;.
666             *
667             * @param layoutSetBranchId the primary key of the current layout set branch
668             * @param groupId the group ID
669             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
670             * @return the previous, current, and next layout set branch
671             * @throws NoSuchLayoutSetBranchException if a layout set branch with the primary key could not be found
672             */
673            @Override
674            public LayoutSetBranch[] filterFindByGroupId_PrevAndNext(
675                    long layoutSetBranchId, long groupId,
676                    OrderByComparator<LayoutSetBranch> orderByComparator)
677                    throws NoSuchLayoutSetBranchException {
678                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
679                            return findByGroupId_PrevAndNext(layoutSetBranchId, groupId,
680                                    orderByComparator);
681                    }
682    
683                    LayoutSetBranch layoutSetBranch = findByPrimaryKey(layoutSetBranchId);
684    
685                    Session session = null;
686    
687                    try {
688                            session = openSession();
689    
690                            LayoutSetBranch[] array = new LayoutSetBranchImpl[3];
691    
692                            array[0] = filterGetByGroupId_PrevAndNext(session, layoutSetBranch,
693                                            groupId, orderByComparator, true);
694    
695                            array[1] = layoutSetBranch;
696    
697                            array[2] = filterGetByGroupId_PrevAndNext(session, layoutSetBranch,
698                                            groupId, orderByComparator, false);
699    
700                            return array;
701                    }
702                    catch (Exception e) {
703                            throw processException(e);
704                    }
705                    finally {
706                            closeSession(session);
707                    }
708            }
709    
710            protected LayoutSetBranch filterGetByGroupId_PrevAndNext(Session session,
711                    LayoutSetBranch layoutSetBranch, long groupId,
712                    OrderByComparator<LayoutSetBranch> orderByComparator, boolean previous) {
713                    StringBundler query = null;
714    
715                    if (orderByComparator != null) {
716                            query = new StringBundler(5 +
717                                            (orderByComparator.getOrderByConditionFields().length * 3) +
718                                            (orderByComparator.getOrderByFields().length * 3));
719                    }
720                    else {
721                            query = new StringBundler(4);
722                    }
723    
724                    if (getDB().isSupportsInlineDistinct()) {
725                            query.append(_FILTER_SQL_SELECT_LAYOUTSETBRANCH_WHERE);
726                    }
727                    else {
728                            query.append(_FILTER_SQL_SELECT_LAYOUTSETBRANCH_NO_INLINE_DISTINCT_WHERE_1);
729                    }
730    
731                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
732    
733                    if (!getDB().isSupportsInlineDistinct()) {
734                            query.append(_FILTER_SQL_SELECT_LAYOUTSETBRANCH_NO_INLINE_DISTINCT_WHERE_2);
735                    }
736    
737                    if (orderByComparator != null) {
738                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
739    
740                            if (orderByConditionFields.length > 0) {
741                                    query.append(WHERE_AND);
742                            }
743    
744                            for (int i = 0; i < orderByConditionFields.length; i++) {
745                                    if (getDB().isSupportsInlineDistinct()) {
746                                            query.append(_ORDER_BY_ENTITY_ALIAS);
747                                    }
748                                    else {
749                                            query.append(_ORDER_BY_ENTITY_TABLE);
750                                    }
751    
752                                    query.append(orderByConditionFields[i]);
753    
754                                    if ((i + 1) < orderByConditionFields.length) {
755                                            if (orderByComparator.isAscending() ^ previous) {
756                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
757                                            }
758                                            else {
759                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
760                                            }
761                                    }
762                                    else {
763                                            if (orderByComparator.isAscending() ^ previous) {
764                                                    query.append(WHERE_GREATER_THAN);
765                                            }
766                                            else {
767                                                    query.append(WHERE_LESSER_THAN);
768                                            }
769                                    }
770                            }
771    
772                            query.append(ORDER_BY_CLAUSE);
773    
774                            String[] orderByFields = orderByComparator.getOrderByFields();
775    
776                            for (int i = 0; i < orderByFields.length; i++) {
777                                    if (getDB().isSupportsInlineDistinct()) {
778                                            query.append(_ORDER_BY_ENTITY_ALIAS);
779                                    }
780                                    else {
781                                            query.append(_ORDER_BY_ENTITY_TABLE);
782                                    }
783    
784                                    query.append(orderByFields[i]);
785    
786                                    if ((i + 1) < orderByFields.length) {
787                                            if (orderByComparator.isAscending() ^ previous) {
788                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
789                                            }
790                                            else {
791                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
792                                            }
793                                    }
794                                    else {
795                                            if (orderByComparator.isAscending() ^ previous) {
796                                                    query.append(ORDER_BY_ASC);
797                                            }
798                                            else {
799                                                    query.append(ORDER_BY_DESC);
800                                            }
801                                    }
802                            }
803                    }
804                    else {
805                            if (getDB().isSupportsInlineDistinct()) {
806                                    query.append(LayoutSetBranchModelImpl.ORDER_BY_JPQL);
807                            }
808                            else {
809                                    query.append(LayoutSetBranchModelImpl.ORDER_BY_SQL);
810                            }
811                    }
812    
813                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
814                                    LayoutSetBranch.class.getName(),
815                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
816    
817                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
818    
819                    q.setFirstResult(0);
820                    q.setMaxResults(2);
821    
822                    if (getDB().isSupportsInlineDistinct()) {
823                            q.addEntity(_FILTER_ENTITY_ALIAS, LayoutSetBranchImpl.class);
824                    }
825                    else {
826                            q.addEntity(_FILTER_ENTITY_TABLE, LayoutSetBranchImpl.class);
827                    }
828    
829                    QueryPos qPos = QueryPos.getInstance(q);
830    
831                    qPos.add(groupId);
832    
833                    if (orderByComparator != null) {
834                            Object[] values = orderByComparator.getOrderByConditionValues(layoutSetBranch);
835    
836                            for (Object value : values) {
837                                    qPos.add(value);
838                            }
839                    }
840    
841                    List<LayoutSetBranch> list = q.list();
842    
843                    if (list.size() == 2) {
844                            return list.get(1);
845                    }
846                    else {
847                            return null;
848                    }
849            }
850    
851            /**
852             * Removes all the layout set branchs where groupId = &#63; from the database.
853             *
854             * @param groupId the group ID
855             */
856            @Override
857            public void removeByGroupId(long groupId) {
858                    for (LayoutSetBranch layoutSetBranch : findByGroupId(groupId,
859                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
860                            remove(layoutSetBranch);
861                    }
862            }
863    
864            /**
865             * Returns the number of layout set branchs where groupId = &#63;.
866             *
867             * @param groupId the group ID
868             * @return the number of matching layout set branchs
869             */
870            @Override
871            public int countByGroupId(long groupId) {
872                    FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
873    
874                    Object[] finderArgs = new Object[] { groupId };
875    
876                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
877    
878                    if (count == null) {
879                            StringBundler query = new StringBundler(2);
880    
881                            query.append(_SQL_COUNT_LAYOUTSETBRANCH_WHERE);
882    
883                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
884    
885                            String sql = query.toString();
886    
887                            Session session = null;
888    
889                            try {
890                                    session = openSession();
891    
892                                    Query q = session.createQuery(sql);
893    
894                                    QueryPos qPos = QueryPos.getInstance(q);
895    
896                                    qPos.add(groupId);
897    
898                                    count = (Long)q.uniqueResult();
899    
900                                    finderCache.putResult(finderPath, finderArgs, count);
901                            }
902                            catch (Exception e) {
903                                    finderCache.removeResult(finderPath, finderArgs);
904    
905                                    throw processException(e);
906                            }
907                            finally {
908                                    closeSession(session);
909                            }
910                    }
911    
912                    return count.intValue();
913            }
914    
915            /**
916             * Returns the number of layout set branchs that the user has permission to view where groupId = &#63;.
917             *
918             * @param groupId the group ID
919             * @return the number of matching layout set branchs that the user has permission to view
920             */
921            @Override
922            public int filterCountByGroupId(long groupId) {
923                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
924                            return countByGroupId(groupId);
925                    }
926    
927                    StringBundler query = new StringBundler(2);
928    
929                    query.append(_FILTER_SQL_COUNT_LAYOUTSETBRANCH_WHERE);
930    
931                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
932    
933                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
934                                    LayoutSetBranch.class.getName(),
935                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
936    
937                    Session session = null;
938    
939                    try {
940                            session = openSession();
941    
942                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
943    
944                            q.addScalar(COUNT_COLUMN_NAME,
945                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
946    
947                            QueryPos qPos = QueryPos.getInstance(q);
948    
949                            qPos.add(groupId);
950    
951                            Long count = (Long)q.uniqueResult();
952    
953                            return count.intValue();
954                    }
955                    catch (Exception e) {
956                            throw processException(e);
957                    }
958                    finally {
959                            closeSession(session);
960                    }
961            }
962    
963            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "layoutSetBranch.groupId = ?";
964            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P = new FinderPath(LayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
965                            LayoutSetBranchModelImpl.FINDER_CACHE_ENABLED,
966                            LayoutSetBranchImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
967                            "findByG_P",
968                            new String[] {
969                                    Long.class.getName(), Boolean.class.getName(),
970                                    
971                            Integer.class.getName(), Integer.class.getName(),
972                                    OrderByComparator.class.getName()
973                            });
974            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P = new FinderPath(LayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
975                            LayoutSetBranchModelImpl.FINDER_CACHE_ENABLED,
976                            LayoutSetBranchImpl.class,
977                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_P",
978                            new String[] { Long.class.getName(), Boolean.class.getName() },
979                            LayoutSetBranchModelImpl.GROUPID_COLUMN_BITMASK |
980                            LayoutSetBranchModelImpl.PRIVATELAYOUT_COLUMN_BITMASK |
981                            LayoutSetBranchModelImpl.NAME_COLUMN_BITMASK);
982            public static final FinderPath FINDER_PATH_COUNT_BY_G_P = new FinderPath(LayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
983                            LayoutSetBranchModelImpl.FINDER_CACHE_ENABLED, Long.class,
984                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P",
985                            new String[] { Long.class.getName(), Boolean.class.getName() });
986    
987            /**
988             * Returns all the layout set branchs where groupId = &#63; and privateLayout = &#63;.
989             *
990             * @param groupId the group ID
991             * @param privateLayout the private layout
992             * @return the matching layout set branchs
993             */
994            @Override
995            public List<LayoutSetBranch> findByG_P(long groupId, boolean privateLayout) {
996                    return findByG_P(groupId, privateLayout, QueryUtil.ALL_POS,
997                            QueryUtil.ALL_POS, null);
998            }
999    
1000            /**
1001             * Returns a range of all the layout set branchs where groupId = &#63; and privateLayout = &#63;.
1002             *
1003             * <p>
1004             * 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 LayoutSetBranchModelImpl}. 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.
1005             * </p>
1006             *
1007             * @param groupId the group ID
1008             * @param privateLayout the private layout
1009             * @param start the lower bound of the range of layout set branchs
1010             * @param end the upper bound of the range of layout set branchs (not inclusive)
1011             * @return the range of matching layout set branchs
1012             */
1013            @Override
1014            public List<LayoutSetBranch> findByG_P(long groupId, boolean privateLayout,
1015                    int start, int end) {
1016                    return findByG_P(groupId, privateLayout, start, end, null);
1017            }
1018    
1019            /**
1020             * Returns an ordered range of all the layout set branchs where groupId = &#63; and privateLayout = &#63;.
1021             *
1022             * <p>
1023             * 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 LayoutSetBranchModelImpl}. 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.
1024             * </p>
1025             *
1026             * @param groupId the group ID
1027             * @param privateLayout the private layout
1028             * @param start the lower bound of the range of layout set branchs
1029             * @param end the upper bound of the range of layout set branchs (not inclusive)
1030             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1031             * @return the ordered range of matching layout set branchs
1032             */
1033            @Override
1034            public List<LayoutSetBranch> findByG_P(long groupId, boolean privateLayout,
1035                    int start, int end, OrderByComparator<LayoutSetBranch> orderByComparator) {
1036                    return findByG_P(groupId, privateLayout, start, end, orderByComparator,
1037                            true);
1038            }
1039    
1040            /**
1041             * Returns an ordered range of all the layout set branchs where groupId = &#63; and privateLayout = &#63;.
1042             *
1043             * <p>
1044             * 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 LayoutSetBranchModelImpl}. 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.
1045             * </p>
1046             *
1047             * @param groupId the group ID
1048             * @param privateLayout the private layout
1049             * @param start the lower bound of the range of layout set branchs
1050             * @param end the upper bound of the range of layout set branchs (not inclusive)
1051             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1052             * @param retrieveFromCache whether to retrieve from the finder cache
1053             * @return the ordered range of matching layout set branchs
1054             */
1055            @Override
1056            public List<LayoutSetBranch> findByG_P(long groupId, boolean privateLayout,
1057                    int start, int end,
1058                    OrderByComparator<LayoutSetBranch> orderByComparator,
1059                    boolean retrieveFromCache) {
1060                    boolean pagination = true;
1061                    FinderPath finderPath = null;
1062                    Object[] finderArgs = null;
1063    
1064                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1065                                    (orderByComparator == null)) {
1066                            pagination = false;
1067                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P;
1068                            finderArgs = new Object[] { groupId, privateLayout };
1069                    }
1070                    else {
1071                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P;
1072                            finderArgs = new Object[] {
1073                                            groupId, privateLayout,
1074                                            
1075                                            start, end, orderByComparator
1076                                    };
1077                    }
1078    
1079                    List<LayoutSetBranch> list = null;
1080    
1081                    if (retrieveFromCache) {
1082                            list = (List<LayoutSetBranch>)finderCache.getResult(finderPath,
1083                                            finderArgs, this);
1084    
1085                            if ((list != null) && !list.isEmpty()) {
1086                                    for (LayoutSetBranch layoutSetBranch : list) {
1087                                            if ((groupId != layoutSetBranch.getGroupId()) ||
1088                                                            (privateLayout != layoutSetBranch.getPrivateLayout())) {
1089                                                    list = null;
1090    
1091                                                    break;
1092                                            }
1093                                    }
1094                            }
1095                    }
1096    
1097                    if (list == null) {
1098                            StringBundler query = null;
1099    
1100                            if (orderByComparator != null) {
1101                                    query = new StringBundler(4 +
1102                                                    (orderByComparator.getOrderByFields().length * 2));
1103                            }
1104                            else {
1105                                    query = new StringBundler(4);
1106                            }
1107    
1108                            query.append(_SQL_SELECT_LAYOUTSETBRANCH_WHERE);
1109    
1110                            query.append(_FINDER_COLUMN_G_P_GROUPID_2);
1111    
1112                            query.append(_FINDER_COLUMN_G_P_PRIVATELAYOUT_2);
1113    
1114                            if (orderByComparator != null) {
1115                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1116                                            orderByComparator);
1117                            }
1118                            else
1119                             if (pagination) {
1120                                    query.append(LayoutSetBranchModelImpl.ORDER_BY_JPQL);
1121                            }
1122    
1123                            String sql = query.toString();
1124    
1125                            Session session = null;
1126    
1127                            try {
1128                                    session = openSession();
1129    
1130                                    Query q = session.createQuery(sql);
1131    
1132                                    QueryPos qPos = QueryPos.getInstance(q);
1133    
1134                                    qPos.add(groupId);
1135    
1136                                    qPos.add(privateLayout);
1137    
1138                                    if (!pagination) {
1139                                            list = (List<LayoutSetBranch>)QueryUtil.list(q,
1140                                                            getDialect(), start, end, false);
1141    
1142                                            Collections.sort(list);
1143    
1144                                            list = Collections.unmodifiableList(list);
1145                                    }
1146                                    else {
1147                                            list = (List<LayoutSetBranch>)QueryUtil.list(q,
1148                                                            getDialect(), start, end);
1149                                    }
1150    
1151                                    cacheResult(list);
1152    
1153                                    finderCache.putResult(finderPath, finderArgs, list);
1154                            }
1155                            catch (Exception e) {
1156                                    finderCache.removeResult(finderPath, finderArgs);
1157    
1158                                    throw processException(e);
1159                            }
1160                            finally {
1161                                    closeSession(session);
1162                            }
1163                    }
1164    
1165                    return list;
1166            }
1167    
1168            /**
1169             * Returns the first layout set branch in the ordered set where groupId = &#63; and privateLayout = &#63;.
1170             *
1171             * @param groupId the group ID
1172             * @param privateLayout the private layout
1173             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1174             * @return the first matching layout set branch
1175             * @throws NoSuchLayoutSetBranchException if a matching layout set branch could not be found
1176             */
1177            @Override
1178            public LayoutSetBranch findByG_P_First(long groupId, boolean privateLayout,
1179                    OrderByComparator<LayoutSetBranch> orderByComparator)
1180                    throws NoSuchLayoutSetBranchException {
1181                    LayoutSetBranch layoutSetBranch = fetchByG_P_First(groupId,
1182                                    privateLayout, orderByComparator);
1183    
1184                    if (layoutSetBranch != null) {
1185                            return layoutSetBranch;
1186                    }
1187    
1188                    StringBundler msg = new StringBundler(6);
1189    
1190                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1191    
1192                    msg.append("groupId=");
1193                    msg.append(groupId);
1194    
1195                    msg.append(", privateLayout=");
1196                    msg.append(privateLayout);
1197    
1198                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1199    
1200                    throw new NoSuchLayoutSetBranchException(msg.toString());
1201            }
1202    
1203            /**
1204             * Returns the first layout set branch in the ordered set where groupId = &#63; and privateLayout = &#63;.
1205             *
1206             * @param groupId the group ID
1207             * @param privateLayout the private layout
1208             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1209             * @return the first matching layout set branch, or <code>null</code> if a matching layout set branch could not be found
1210             */
1211            @Override
1212            public LayoutSetBranch fetchByG_P_First(long groupId,
1213                    boolean privateLayout,
1214                    OrderByComparator<LayoutSetBranch> orderByComparator) {
1215                    List<LayoutSetBranch> list = findByG_P(groupId, privateLayout, 0, 1,
1216                                    orderByComparator);
1217    
1218                    if (!list.isEmpty()) {
1219                            return list.get(0);
1220                    }
1221    
1222                    return null;
1223            }
1224    
1225            /**
1226             * Returns the last layout set branch in the ordered set where groupId = &#63; and privateLayout = &#63;.
1227             *
1228             * @param groupId the group ID
1229             * @param privateLayout the private layout
1230             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1231             * @return the last matching layout set branch
1232             * @throws NoSuchLayoutSetBranchException if a matching layout set branch could not be found
1233             */
1234            @Override
1235            public LayoutSetBranch findByG_P_Last(long groupId, boolean privateLayout,
1236                    OrderByComparator<LayoutSetBranch> orderByComparator)
1237                    throws NoSuchLayoutSetBranchException {
1238                    LayoutSetBranch layoutSetBranch = fetchByG_P_Last(groupId,
1239                                    privateLayout, orderByComparator);
1240    
1241                    if (layoutSetBranch != null) {
1242                            return layoutSetBranch;
1243                    }
1244    
1245                    StringBundler msg = new StringBundler(6);
1246    
1247                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1248    
1249                    msg.append("groupId=");
1250                    msg.append(groupId);
1251    
1252                    msg.append(", privateLayout=");
1253                    msg.append(privateLayout);
1254    
1255                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1256    
1257                    throw new NoSuchLayoutSetBranchException(msg.toString());
1258            }
1259    
1260            /**
1261             * Returns the last layout set branch in the ordered set where groupId = &#63; and privateLayout = &#63;.
1262             *
1263             * @param groupId the group ID
1264             * @param privateLayout the private layout
1265             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1266             * @return the last matching layout set branch, or <code>null</code> if a matching layout set branch could not be found
1267             */
1268            @Override
1269            public LayoutSetBranch fetchByG_P_Last(long groupId, boolean privateLayout,
1270                    OrderByComparator<LayoutSetBranch> orderByComparator) {
1271                    int count = countByG_P(groupId, privateLayout);
1272    
1273                    if (count == 0) {
1274                            return null;
1275                    }
1276    
1277                    List<LayoutSetBranch> list = findByG_P(groupId, privateLayout,
1278                                    count - 1, count, orderByComparator);
1279    
1280                    if (!list.isEmpty()) {
1281                            return list.get(0);
1282                    }
1283    
1284                    return null;
1285            }
1286    
1287            /**
1288             * Returns the layout set branchs before and after the current layout set branch in the ordered set where groupId = &#63; and privateLayout = &#63;.
1289             *
1290             * @param layoutSetBranchId the primary key of the current layout set branch
1291             * @param groupId the group ID
1292             * @param privateLayout the private layout
1293             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1294             * @return the previous, current, and next layout set branch
1295             * @throws NoSuchLayoutSetBranchException if a layout set branch with the primary key could not be found
1296             */
1297            @Override
1298            public LayoutSetBranch[] findByG_P_PrevAndNext(long layoutSetBranchId,
1299                    long groupId, boolean privateLayout,
1300                    OrderByComparator<LayoutSetBranch> orderByComparator)
1301                    throws NoSuchLayoutSetBranchException {
1302                    LayoutSetBranch layoutSetBranch = findByPrimaryKey(layoutSetBranchId);
1303    
1304                    Session session = null;
1305    
1306                    try {
1307                            session = openSession();
1308    
1309                            LayoutSetBranch[] array = new LayoutSetBranchImpl[3];
1310    
1311                            array[0] = getByG_P_PrevAndNext(session, layoutSetBranch, groupId,
1312                                            privateLayout, orderByComparator, true);
1313    
1314                            array[1] = layoutSetBranch;
1315    
1316                            array[2] = getByG_P_PrevAndNext(session, layoutSetBranch, groupId,
1317                                            privateLayout, orderByComparator, false);
1318    
1319                            return array;
1320                    }
1321                    catch (Exception e) {
1322                            throw processException(e);
1323                    }
1324                    finally {
1325                            closeSession(session);
1326                    }
1327            }
1328    
1329            protected LayoutSetBranch getByG_P_PrevAndNext(Session session,
1330                    LayoutSetBranch layoutSetBranch, long groupId, boolean privateLayout,
1331                    OrderByComparator<LayoutSetBranch> orderByComparator, boolean previous) {
1332                    StringBundler query = null;
1333    
1334                    if (orderByComparator != null) {
1335                            query = new StringBundler(5 +
1336                                            (orderByComparator.getOrderByConditionFields().length * 3) +
1337                                            (orderByComparator.getOrderByFields().length * 3));
1338                    }
1339                    else {
1340                            query = new StringBundler(4);
1341                    }
1342    
1343                    query.append(_SQL_SELECT_LAYOUTSETBRANCH_WHERE);
1344    
1345                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
1346    
1347                    query.append(_FINDER_COLUMN_G_P_PRIVATELAYOUT_2);
1348    
1349                    if (orderByComparator != null) {
1350                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1351    
1352                            if (orderByConditionFields.length > 0) {
1353                                    query.append(WHERE_AND);
1354                            }
1355    
1356                            for (int i = 0; i < orderByConditionFields.length; i++) {
1357                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1358                                    query.append(orderByConditionFields[i]);
1359    
1360                                    if ((i + 1) < orderByConditionFields.length) {
1361                                            if (orderByComparator.isAscending() ^ previous) {
1362                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1363                                            }
1364                                            else {
1365                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1366                                            }
1367                                    }
1368                                    else {
1369                                            if (orderByComparator.isAscending() ^ previous) {
1370                                                    query.append(WHERE_GREATER_THAN);
1371                                            }
1372                                            else {
1373                                                    query.append(WHERE_LESSER_THAN);
1374                                            }
1375                                    }
1376                            }
1377    
1378                            query.append(ORDER_BY_CLAUSE);
1379    
1380                            String[] orderByFields = orderByComparator.getOrderByFields();
1381    
1382                            for (int i = 0; i < orderByFields.length; i++) {
1383                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1384                                    query.append(orderByFields[i]);
1385    
1386                                    if ((i + 1) < orderByFields.length) {
1387                                            if (orderByComparator.isAscending() ^ previous) {
1388                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1389                                            }
1390                                            else {
1391                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1392                                            }
1393                                    }
1394                                    else {
1395                                            if (orderByComparator.isAscending() ^ previous) {
1396                                                    query.append(ORDER_BY_ASC);
1397                                            }
1398                                            else {
1399                                                    query.append(ORDER_BY_DESC);
1400                                            }
1401                                    }
1402                            }
1403                    }
1404                    else {
1405                            query.append(LayoutSetBranchModelImpl.ORDER_BY_JPQL);
1406                    }
1407    
1408                    String sql = query.toString();
1409    
1410                    Query q = session.createQuery(sql);
1411    
1412                    q.setFirstResult(0);
1413                    q.setMaxResults(2);
1414    
1415                    QueryPos qPos = QueryPos.getInstance(q);
1416    
1417                    qPos.add(groupId);
1418    
1419                    qPos.add(privateLayout);
1420    
1421                    if (orderByComparator != null) {
1422                            Object[] values = orderByComparator.getOrderByConditionValues(layoutSetBranch);
1423    
1424                            for (Object value : values) {
1425                                    qPos.add(value);
1426                            }
1427                    }
1428    
1429                    List<LayoutSetBranch> list = q.list();
1430    
1431                    if (list.size() == 2) {
1432                            return list.get(1);
1433                    }
1434                    else {
1435                            return null;
1436                    }
1437            }
1438    
1439            /**
1440             * Returns all the layout set branchs that the user has permission to view where groupId = &#63; and privateLayout = &#63;.
1441             *
1442             * @param groupId the group ID
1443             * @param privateLayout the private layout
1444             * @return the matching layout set branchs that the user has permission to view
1445             */
1446            @Override
1447            public List<LayoutSetBranch> filterFindByG_P(long groupId,
1448                    boolean privateLayout) {
1449                    return filterFindByG_P(groupId, privateLayout, QueryUtil.ALL_POS,
1450                            QueryUtil.ALL_POS, null);
1451            }
1452    
1453            /**
1454             * Returns a range of all the layout set branchs that the user has permission to view where groupId = &#63; and privateLayout = &#63;.
1455             *
1456             * <p>
1457             * 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 LayoutSetBranchModelImpl}. 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.
1458             * </p>
1459             *
1460             * @param groupId the group ID
1461             * @param privateLayout the private layout
1462             * @param start the lower bound of the range of layout set branchs
1463             * @param end the upper bound of the range of layout set branchs (not inclusive)
1464             * @return the range of matching layout set branchs that the user has permission to view
1465             */
1466            @Override
1467            public List<LayoutSetBranch> filterFindByG_P(long groupId,
1468                    boolean privateLayout, int start, int end) {
1469                    return filterFindByG_P(groupId, privateLayout, start, end, null);
1470            }
1471    
1472            /**
1473             * Returns an ordered range of all the layout set branchs that the user has permissions to view where groupId = &#63; and privateLayout = &#63;.
1474             *
1475             * <p>
1476             * 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 LayoutSetBranchModelImpl}. 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.
1477             * </p>
1478             *
1479             * @param groupId the group ID
1480             * @param privateLayout the private layout
1481             * @param start the lower bound of the range of layout set branchs
1482             * @param end the upper bound of the range of layout set branchs (not inclusive)
1483             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1484             * @return the ordered range of matching layout set branchs that the user has permission to view
1485             */
1486            @Override
1487            public List<LayoutSetBranch> filterFindByG_P(long groupId,
1488                    boolean privateLayout, int start, int end,
1489                    OrderByComparator<LayoutSetBranch> orderByComparator) {
1490                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1491                            return findByG_P(groupId, privateLayout, start, end,
1492                                    orderByComparator);
1493                    }
1494    
1495                    StringBundler query = null;
1496    
1497                    if (orderByComparator != null) {
1498                            query = new StringBundler(4 +
1499                                            (orderByComparator.getOrderByFields().length * 2));
1500                    }
1501                    else {
1502                            query = new StringBundler(5);
1503                    }
1504    
1505                    if (getDB().isSupportsInlineDistinct()) {
1506                            query.append(_FILTER_SQL_SELECT_LAYOUTSETBRANCH_WHERE);
1507                    }
1508                    else {
1509                            query.append(_FILTER_SQL_SELECT_LAYOUTSETBRANCH_NO_INLINE_DISTINCT_WHERE_1);
1510                    }
1511    
1512                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
1513    
1514                    query.append(_FINDER_COLUMN_G_P_PRIVATELAYOUT_2);
1515    
1516                    if (!getDB().isSupportsInlineDistinct()) {
1517                            query.append(_FILTER_SQL_SELECT_LAYOUTSETBRANCH_NO_INLINE_DISTINCT_WHERE_2);
1518                    }
1519    
1520                    if (orderByComparator != null) {
1521                            if (getDB().isSupportsInlineDistinct()) {
1522                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1523                                            orderByComparator, true);
1524                            }
1525                            else {
1526                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1527                                            orderByComparator, true);
1528                            }
1529                    }
1530                    else {
1531                            if (getDB().isSupportsInlineDistinct()) {
1532                                    query.append(LayoutSetBranchModelImpl.ORDER_BY_JPQL);
1533                            }
1534                            else {
1535                                    query.append(LayoutSetBranchModelImpl.ORDER_BY_SQL);
1536                            }
1537                    }
1538    
1539                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1540                                    LayoutSetBranch.class.getName(),
1541                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1542    
1543                    Session session = null;
1544    
1545                    try {
1546                            session = openSession();
1547    
1548                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
1549    
1550                            if (getDB().isSupportsInlineDistinct()) {
1551                                    q.addEntity(_FILTER_ENTITY_ALIAS, LayoutSetBranchImpl.class);
1552                            }
1553                            else {
1554                                    q.addEntity(_FILTER_ENTITY_TABLE, LayoutSetBranchImpl.class);
1555                            }
1556    
1557                            QueryPos qPos = QueryPos.getInstance(q);
1558    
1559                            qPos.add(groupId);
1560    
1561                            qPos.add(privateLayout);
1562    
1563                            return (List<LayoutSetBranch>)QueryUtil.list(q, getDialect(),
1564                                    start, end);
1565                    }
1566                    catch (Exception e) {
1567                            throw processException(e);
1568                    }
1569                    finally {
1570                            closeSession(session);
1571                    }
1572            }
1573    
1574            /**
1575             * Returns the layout set branchs before and after the current layout set branch in the ordered set of layout set branchs that the user has permission to view where groupId = &#63; and privateLayout = &#63;.
1576             *
1577             * @param layoutSetBranchId the primary key of the current layout set branch
1578             * @param groupId the group ID
1579             * @param privateLayout the private layout
1580             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1581             * @return the previous, current, and next layout set branch
1582             * @throws NoSuchLayoutSetBranchException if a layout set branch with the primary key could not be found
1583             */
1584            @Override
1585            public LayoutSetBranch[] filterFindByG_P_PrevAndNext(
1586                    long layoutSetBranchId, long groupId, boolean privateLayout,
1587                    OrderByComparator<LayoutSetBranch> orderByComparator)
1588                    throws NoSuchLayoutSetBranchException {
1589                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1590                            return findByG_P_PrevAndNext(layoutSetBranchId, groupId,
1591                                    privateLayout, orderByComparator);
1592                    }
1593    
1594                    LayoutSetBranch layoutSetBranch = findByPrimaryKey(layoutSetBranchId);
1595    
1596                    Session session = null;
1597    
1598                    try {
1599                            session = openSession();
1600    
1601                            LayoutSetBranch[] array = new LayoutSetBranchImpl[3];
1602    
1603                            array[0] = filterGetByG_P_PrevAndNext(session, layoutSetBranch,
1604                                            groupId, privateLayout, orderByComparator, true);
1605    
1606                            array[1] = layoutSetBranch;
1607    
1608                            array[2] = filterGetByG_P_PrevAndNext(session, layoutSetBranch,
1609                                            groupId, privateLayout, orderByComparator, false);
1610    
1611                            return array;
1612                    }
1613                    catch (Exception e) {
1614                            throw processException(e);
1615                    }
1616                    finally {
1617                            closeSession(session);
1618                    }
1619            }
1620    
1621            protected LayoutSetBranch filterGetByG_P_PrevAndNext(Session session,
1622                    LayoutSetBranch layoutSetBranch, long groupId, boolean privateLayout,
1623                    OrderByComparator<LayoutSetBranch> orderByComparator, boolean previous) {
1624                    StringBundler query = null;
1625    
1626                    if (orderByComparator != null) {
1627                            query = new StringBundler(6 +
1628                                            (orderByComparator.getOrderByConditionFields().length * 3) +
1629                                            (orderByComparator.getOrderByFields().length * 3));
1630                    }
1631                    else {
1632                            query = new StringBundler(5);
1633                    }
1634    
1635                    if (getDB().isSupportsInlineDistinct()) {
1636                            query.append(_FILTER_SQL_SELECT_LAYOUTSETBRANCH_WHERE);
1637                    }
1638                    else {
1639                            query.append(_FILTER_SQL_SELECT_LAYOUTSETBRANCH_NO_INLINE_DISTINCT_WHERE_1);
1640                    }
1641    
1642                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
1643    
1644                    query.append(_FINDER_COLUMN_G_P_PRIVATELAYOUT_2);
1645    
1646                    if (!getDB().isSupportsInlineDistinct()) {
1647                            query.append(_FILTER_SQL_SELECT_LAYOUTSETBRANCH_NO_INLINE_DISTINCT_WHERE_2);
1648                    }
1649    
1650                    if (orderByComparator != null) {
1651                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1652    
1653                            if (orderByConditionFields.length > 0) {
1654                                    query.append(WHERE_AND);
1655                            }
1656    
1657                            for (int i = 0; i < orderByConditionFields.length; i++) {
1658                                    if (getDB().isSupportsInlineDistinct()) {
1659                                            query.append(_ORDER_BY_ENTITY_ALIAS);
1660                                    }
1661                                    else {
1662                                            query.append(_ORDER_BY_ENTITY_TABLE);
1663                                    }
1664    
1665                                    query.append(orderByConditionFields[i]);
1666    
1667                                    if ((i + 1) < orderByConditionFields.length) {
1668                                            if (orderByComparator.isAscending() ^ previous) {
1669                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1670                                            }
1671                                            else {
1672                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1673                                            }
1674                                    }
1675                                    else {
1676                                            if (orderByComparator.isAscending() ^ previous) {
1677                                                    query.append(WHERE_GREATER_THAN);
1678                                            }
1679                                            else {
1680                                                    query.append(WHERE_LESSER_THAN);
1681                                            }
1682                                    }
1683                            }
1684    
1685                            query.append(ORDER_BY_CLAUSE);
1686    
1687                            String[] orderByFields = orderByComparator.getOrderByFields();
1688    
1689                            for (int i = 0; i < orderByFields.length; i++) {
1690                                    if (getDB().isSupportsInlineDistinct()) {
1691                                            query.append(_ORDER_BY_ENTITY_ALIAS);
1692                                    }
1693                                    else {
1694                                            query.append(_ORDER_BY_ENTITY_TABLE);
1695                                    }
1696    
1697                                    query.append(orderByFields[i]);
1698    
1699                                    if ((i + 1) < orderByFields.length) {
1700                                            if (orderByComparator.isAscending() ^ previous) {
1701                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1702                                            }
1703                                            else {
1704                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1705                                            }
1706                                    }
1707                                    else {
1708                                            if (orderByComparator.isAscending() ^ previous) {
1709                                                    query.append(ORDER_BY_ASC);
1710                                            }
1711                                            else {
1712                                                    query.append(ORDER_BY_DESC);
1713                                            }
1714                                    }
1715                            }
1716                    }
1717                    else {
1718                            if (getDB().isSupportsInlineDistinct()) {
1719                                    query.append(LayoutSetBranchModelImpl.ORDER_BY_JPQL);
1720                            }
1721                            else {
1722                                    query.append(LayoutSetBranchModelImpl.ORDER_BY_SQL);
1723                            }
1724                    }
1725    
1726                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1727                                    LayoutSetBranch.class.getName(),
1728                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1729    
1730                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
1731    
1732                    q.setFirstResult(0);
1733                    q.setMaxResults(2);
1734    
1735                    if (getDB().isSupportsInlineDistinct()) {
1736                            q.addEntity(_FILTER_ENTITY_ALIAS, LayoutSetBranchImpl.class);
1737                    }
1738                    else {
1739                            q.addEntity(_FILTER_ENTITY_TABLE, LayoutSetBranchImpl.class);
1740                    }
1741    
1742                    QueryPos qPos = QueryPos.getInstance(q);
1743    
1744                    qPos.add(groupId);
1745    
1746                    qPos.add(privateLayout);
1747    
1748                    if (orderByComparator != null) {
1749                            Object[] values = orderByComparator.getOrderByConditionValues(layoutSetBranch);
1750    
1751                            for (Object value : values) {
1752                                    qPos.add(value);
1753                            }
1754                    }
1755    
1756                    List<LayoutSetBranch> list = q.list();
1757    
1758                    if (list.size() == 2) {
1759                            return list.get(1);
1760                    }
1761                    else {
1762                            return null;
1763                    }
1764            }
1765    
1766            /**
1767             * Removes all the layout set branchs where groupId = &#63; and privateLayout = &#63; from the database.
1768             *
1769             * @param groupId the group ID
1770             * @param privateLayout the private layout
1771             */
1772            @Override
1773            public void removeByG_P(long groupId, boolean privateLayout) {
1774                    for (LayoutSetBranch layoutSetBranch : findByG_P(groupId,
1775                                    privateLayout, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1776                            remove(layoutSetBranch);
1777                    }
1778            }
1779    
1780            /**
1781             * Returns the number of layout set branchs where groupId = &#63; and privateLayout = &#63;.
1782             *
1783             * @param groupId the group ID
1784             * @param privateLayout the private layout
1785             * @return the number of matching layout set branchs
1786             */
1787            @Override
1788            public int countByG_P(long groupId, boolean privateLayout) {
1789                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_P;
1790    
1791                    Object[] finderArgs = new Object[] { groupId, privateLayout };
1792    
1793                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1794    
1795                    if (count == null) {
1796                            StringBundler query = new StringBundler(3);
1797    
1798                            query.append(_SQL_COUNT_LAYOUTSETBRANCH_WHERE);
1799    
1800                            query.append(_FINDER_COLUMN_G_P_GROUPID_2);
1801    
1802                            query.append(_FINDER_COLUMN_G_P_PRIVATELAYOUT_2);
1803    
1804                            String sql = query.toString();
1805    
1806                            Session session = null;
1807    
1808                            try {
1809                                    session = openSession();
1810    
1811                                    Query q = session.createQuery(sql);
1812    
1813                                    QueryPos qPos = QueryPos.getInstance(q);
1814    
1815                                    qPos.add(groupId);
1816    
1817                                    qPos.add(privateLayout);
1818    
1819                                    count = (Long)q.uniqueResult();
1820    
1821                                    finderCache.putResult(finderPath, finderArgs, count);
1822                            }
1823                            catch (Exception e) {
1824                                    finderCache.removeResult(finderPath, finderArgs);
1825    
1826                                    throw processException(e);
1827                            }
1828                            finally {
1829                                    closeSession(session);
1830                            }
1831                    }
1832    
1833                    return count.intValue();
1834            }
1835    
1836            /**
1837             * Returns the number of layout set branchs that the user has permission to view where groupId = &#63; and privateLayout = &#63;.
1838             *
1839             * @param groupId the group ID
1840             * @param privateLayout the private layout
1841             * @return the number of matching layout set branchs that the user has permission to view
1842             */
1843            @Override
1844            public int filterCountByG_P(long groupId, boolean privateLayout) {
1845                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1846                            return countByG_P(groupId, privateLayout);
1847                    }
1848    
1849                    StringBundler query = new StringBundler(3);
1850    
1851                    query.append(_FILTER_SQL_COUNT_LAYOUTSETBRANCH_WHERE);
1852    
1853                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
1854    
1855                    query.append(_FINDER_COLUMN_G_P_PRIVATELAYOUT_2);
1856    
1857                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1858                                    LayoutSetBranch.class.getName(),
1859                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1860    
1861                    Session session = null;
1862    
1863                    try {
1864                            session = openSession();
1865    
1866                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
1867    
1868                            q.addScalar(COUNT_COLUMN_NAME,
1869                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
1870    
1871                            QueryPos qPos = QueryPos.getInstance(q);
1872    
1873                            qPos.add(groupId);
1874    
1875                            qPos.add(privateLayout);
1876    
1877                            Long count = (Long)q.uniqueResult();
1878    
1879                            return count.intValue();
1880                    }
1881                    catch (Exception e) {
1882                            throw processException(e);
1883                    }
1884                    finally {
1885                            closeSession(session);
1886                    }
1887            }
1888    
1889            private static final String _FINDER_COLUMN_G_P_GROUPID_2 = "layoutSetBranch.groupId = ? AND ";
1890            private static final String _FINDER_COLUMN_G_P_PRIVATELAYOUT_2 = "layoutSetBranch.privateLayout = ?";
1891            public static final FinderPath FINDER_PATH_FETCH_BY_G_P_N = new FinderPath(LayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
1892                            LayoutSetBranchModelImpl.FINDER_CACHE_ENABLED,
1893                            LayoutSetBranchImpl.class, FINDER_CLASS_NAME_ENTITY,
1894                            "fetchByG_P_N",
1895                            new String[] {
1896                                    Long.class.getName(), Boolean.class.getName(),
1897                                    String.class.getName()
1898                            },
1899                            LayoutSetBranchModelImpl.GROUPID_COLUMN_BITMASK |
1900                            LayoutSetBranchModelImpl.PRIVATELAYOUT_COLUMN_BITMASK |
1901                            LayoutSetBranchModelImpl.NAME_COLUMN_BITMASK);
1902            public static final FinderPath FINDER_PATH_COUNT_BY_G_P_N = new FinderPath(LayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
1903                            LayoutSetBranchModelImpl.FINDER_CACHE_ENABLED, Long.class,
1904                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P_N",
1905                            new String[] {
1906                                    Long.class.getName(), Boolean.class.getName(),
1907                                    String.class.getName()
1908                            });
1909    
1910            /**
1911             * Returns the layout set branch where groupId = &#63; and privateLayout = &#63; and name = &#63; or throws a {@link NoSuchLayoutSetBranchException} if it could not be found.
1912             *
1913             * @param groupId the group ID
1914             * @param privateLayout the private layout
1915             * @param name the name
1916             * @return the matching layout set branch
1917             * @throws NoSuchLayoutSetBranchException if a matching layout set branch could not be found
1918             */
1919            @Override
1920            public LayoutSetBranch findByG_P_N(long groupId, boolean privateLayout,
1921                    String name) throws NoSuchLayoutSetBranchException {
1922                    LayoutSetBranch layoutSetBranch = fetchByG_P_N(groupId, privateLayout,
1923                                    name);
1924    
1925                    if (layoutSetBranch == null) {
1926                            StringBundler msg = new StringBundler(8);
1927    
1928                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1929    
1930                            msg.append("groupId=");
1931                            msg.append(groupId);
1932    
1933                            msg.append(", privateLayout=");
1934                            msg.append(privateLayout);
1935    
1936                            msg.append(", name=");
1937                            msg.append(name);
1938    
1939                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1940    
1941                            if (_log.isWarnEnabled()) {
1942                                    _log.warn(msg.toString());
1943                            }
1944    
1945                            throw new NoSuchLayoutSetBranchException(msg.toString());
1946                    }
1947    
1948                    return layoutSetBranch;
1949            }
1950    
1951            /**
1952             * Returns the layout set branch where groupId = &#63; and privateLayout = &#63; and name = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
1953             *
1954             * @param groupId the group ID
1955             * @param privateLayout the private layout
1956             * @param name the name
1957             * @return the matching layout set branch, or <code>null</code> if a matching layout set branch could not be found
1958             */
1959            @Override
1960            public LayoutSetBranch fetchByG_P_N(long groupId, boolean privateLayout,
1961                    String name) {
1962                    return fetchByG_P_N(groupId, privateLayout, name, true);
1963            }
1964    
1965            /**
1966             * Returns the layout set branch where groupId = &#63; and privateLayout = &#63; and name = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
1967             *
1968             * @param groupId the group ID
1969             * @param privateLayout the private layout
1970             * @param name the name
1971             * @param retrieveFromCache whether to retrieve from the finder cache
1972             * @return the matching layout set branch, or <code>null</code> if a matching layout set branch could not be found
1973             */
1974            @Override
1975            public LayoutSetBranch fetchByG_P_N(long groupId, boolean privateLayout,
1976                    String name, boolean retrieveFromCache) {
1977                    Object[] finderArgs = new Object[] { groupId, privateLayout, name };
1978    
1979                    Object result = null;
1980    
1981                    if (retrieveFromCache) {
1982                            result = finderCache.getResult(FINDER_PATH_FETCH_BY_G_P_N,
1983                                            finderArgs, this);
1984                    }
1985    
1986                    if (result instanceof LayoutSetBranch) {
1987                            LayoutSetBranch layoutSetBranch = (LayoutSetBranch)result;
1988    
1989                            if ((groupId != layoutSetBranch.getGroupId()) ||
1990                                            (privateLayout != layoutSetBranch.getPrivateLayout()) ||
1991                                            !Validator.equals(name, layoutSetBranch.getName())) {
1992                                    result = null;
1993                            }
1994                    }
1995    
1996                    if (result == null) {
1997                            StringBundler query = new StringBundler(5);
1998    
1999                            query.append(_SQL_SELECT_LAYOUTSETBRANCH_WHERE);
2000    
2001                            query.append(_FINDER_COLUMN_G_P_N_GROUPID_2);
2002    
2003                            query.append(_FINDER_COLUMN_G_P_N_PRIVATELAYOUT_2);
2004    
2005                            boolean bindName = false;
2006    
2007                            if (name == null) {
2008                                    query.append(_FINDER_COLUMN_G_P_N_NAME_1);
2009                            }
2010                            else if (name.equals(StringPool.BLANK)) {
2011                                    query.append(_FINDER_COLUMN_G_P_N_NAME_3);
2012                            }
2013                            else {
2014                                    bindName = true;
2015    
2016                                    query.append(_FINDER_COLUMN_G_P_N_NAME_2);
2017                            }
2018    
2019                            String sql = query.toString();
2020    
2021                            Session session = null;
2022    
2023                            try {
2024                                    session = openSession();
2025    
2026                                    Query q = session.createQuery(sql);
2027    
2028                                    QueryPos qPos = QueryPos.getInstance(q);
2029    
2030                                    qPos.add(groupId);
2031    
2032                                    qPos.add(privateLayout);
2033    
2034                                    if (bindName) {
2035                                            qPos.add(name);
2036                                    }
2037    
2038                                    List<LayoutSetBranch> list = q.list();
2039    
2040                                    if (list.isEmpty()) {
2041                                            finderCache.putResult(FINDER_PATH_FETCH_BY_G_P_N,
2042                                                    finderArgs, list);
2043                                    }
2044                                    else {
2045                                            LayoutSetBranch layoutSetBranch = list.get(0);
2046    
2047                                            result = layoutSetBranch;
2048    
2049                                            cacheResult(layoutSetBranch);
2050    
2051                                            if ((layoutSetBranch.getGroupId() != groupId) ||
2052                                                            (layoutSetBranch.getPrivateLayout() != privateLayout) ||
2053                                                            (layoutSetBranch.getName() == null) ||
2054                                                            !layoutSetBranch.getName().equals(name)) {
2055                                                    finderCache.putResult(FINDER_PATH_FETCH_BY_G_P_N,
2056                                                            finderArgs, layoutSetBranch);
2057                                            }
2058                                    }
2059                            }
2060                            catch (Exception e) {
2061                                    finderCache.removeResult(FINDER_PATH_FETCH_BY_G_P_N, finderArgs);
2062    
2063                                    throw processException(e);
2064                            }
2065                            finally {
2066                                    closeSession(session);
2067                            }
2068                    }
2069    
2070                    if (result instanceof List<?>) {
2071                            return null;
2072                    }
2073                    else {
2074                            return (LayoutSetBranch)result;
2075                    }
2076            }
2077    
2078            /**
2079             * Removes the layout set branch where groupId = &#63; and privateLayout = &#63; and name = &#63; from the database.
2080             *
2081             * @param groupId the group ID
2082             * @param privateLayout the private layout
2083             * @param name the name
2084             * @return the layout set branch that was removed
2085             */
2086            @Override
2087            public LayoutSetBranch removeByG_P_N(long groupId, boolean privateLayout,
2088                    String name) throws NoSuchLayoutSetBranchException {
2089                    LayoutSetBranch layoutSetBranch = findByG_P_N(groupId, privateLayout,
2090                                    name);
2091    
2092                    return remove(layoutSetBranch);
2093            }
2094    
2095            /**
2096             * Returns the number of layout set branchs where groupId = &#63; and privateLayout = &#63; and name = &#63;.
2097             *
2098             * @param groupId the group ID
2099             * @param privateLayout the private layout
2100             * @param name the name
2101             * @return the number of matching layout set branchs
2102             */
2103            @Override
2104            public int countByG_P_N(long groupId, boolean privateLayout, String name) {
2105                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_P_N;
2106    
2107                    Object[] finderArgs = new Object[] { groupId, privateLayout, name };
2108    
2109                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
2110    
2111                    if (count == null) {
2112                            StringBundler query = new StringBundler(4);
2113    
2114                            query.append(_SQL_COUNT_LAYOUTSETBRANCH_WHERE);
2115    
2116                            query.append(_FINDER_COLUMN_G_P_N_GROUPID_2);
2117    
2118                            query.append(_FINDER_COLUMN_G_P_N_PRIVATELAYOUT_2);
2119    
2120                            boolean bindName = false;
2121    
2122                            if (name == null) {
2123                                    query.append(_FINDER_COLUMN_G_P_N_NAME_1);
2124                            }
2125                            else if (name.equals(StringPool.BLANK)) {
2126                                    query.append(_FINDER_COLUMN_G_P_N_NAME_3);
2127                            }
2128                            else {
2129                                    bindName = true;
2130    
2131                                    query.append(_FINDER_COLUMN_G_P_N_NAME_2);
2132                            }
2133    
2134                            String sql = query.toString();
2135    
2136                            Session session = null;
2137    
2138                            try {
2139                                    session = openSession();
2140    
2141                                    Query q = session.createQuery(sql);
2142    
2143                                    QueryPos qPos = QueryPos.getInstance(q);
2144    
2145                                    qPos.add(groupId);
2146    
2147                                    qPos.add(privateLayout);
2148    
2149                                    if (bindName) {
2150                                            qPos.add(name);
2151                                    }
2152    
2153                                    count = (Long)q.uniqueResult();
2154    
2155                                    finderCache.putResult(finderPath, finderArgs, count);
2156                            }
2157                            catch (Exception e) {
2158                                    finderCache.removeResult(finderPath, finderArgs);
2159    
2160                                    throw processException(e);
2161                            }
2162                            finally {
2163                                    closeSession(session);
2164                            }
2165                    }
2166    
2167                    return count.intValue();
2168            }
2169    
2170            private static final String _FINDER_COLUMN_G_P_N_GROUPID_2 = "layoutSetBranch.groupId = ? AND ";
2171            private static final String _FINDER_COLUMN_G_P_N_PRIVATELAYOUT_2 = "layoutSetBranch.privateLayout = ? AND ";
2172            private static final String _FINDER_COLUMN_G_P_N_NAME_1 = "layoutSetBranch.name IS NULL";
2173            private static final String _FINDER_COLUMN_G_P_N_NAME_2 = "layoutSetBranch.name = ?";
2174            private static final String _FINDER_COLUMN_G_P_N_NAME_3 = "(layoutSetBranch.name IS NULL OR layoutSetBranch.name = '')";
2175            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_M = new FinderPath(LayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
2176                            LayoutSetBranchModelImpl.FINDER_CACHE_ENABLED,
2177                            LayoutSetBranchImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
2178                            "findByG_P_M",
2179                            new String[] {
2180                                    Long.class.getName(), Boolean.class.getName(),
2181                                    Boolean.class.getName(),
2182                                    
2183                            Integer.class.getName(), Integer.class.getName(),
2184                                    OrderByComparator.class.getName()
2185                            });
2186            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_M = new FinderPath(LayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
2187                            LayoutSetBranchModelImpl.FINDER_CACHE_ENABLED,
2188                            LayoutSetBranchImpl.class,
2189                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_P_M",
2190                            new String[] {
2191                                    Long.class.getName(), Boolean.class.getName(),
2192                                    Boolean.class.getName()
2193                            },
2194                            LayoutSetBranchModelImpl.GROUPID_COLUMN_BITMASK |
2195                            LayoutSetBranchModelImpl.PRIVATELAYOUT_COLUMN_BITMASK |
2196                            LayoutSetBranchModelImpl.MASTER_COLUMN_BITMASK |
2197                            LayoutSetBranchModelImpl.NAME_COLUMN_BITMASK);
2198            public static final FinderPath FINDER_PATH_COUNT_BY_G_P_M = new FinderPath(LayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
2199                            LayoutSetBranchModelImpl.FINDER_CACHE_ENABLED, Long.class,
2200                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P_M",
2201                            new String[] {
2202                                    Long.class.getName(), Boolean.class.getName(),
2203                                    Boolean.class.getName()
2204                            });
2205    
2206            /**
2207             * Returns all the layout set branchs where groupId = &#63; and privateLayout = &#63; and master = &#63;.
2208             *
2209             * @param groupId the group ID
2210             * @param privateLayout the private layout
2211             * @param master the master
2212             * @return the matching layout set branchs
2213             */
2214            @Override
2215            public List<LayoutSetBranch> findByG_P_M(long groupId,
2216                    boolean privateLayout, boolean master) {
2217                    return findByG_P_M(groupId, privateLayout, master, QueryUtil.ALL_POS,
2218                            QueryUtil.ALL_POS, null);
2219            }
2220    
2221            /**
2222             * Returns a range of all the layout set branchs where groupId = &#63; and privateLayout = &#63; and master = &#63;.
2223             *
2224             * <p>
2225             * 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 LayoutSetBranchModelImpl}. 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.
2226             * </p>
2227             *
2228             * @param groupId the group ID
2229             * @param privateLayout the private layout
2230             * @param master the master
2231             * @param start the lower bound of the range of layout set branchs
2232             * @param end the upper bound of the range of layout set branchs (not inclusive)
2233             * @return the range of matching layout set branchs
2234             */
2235            @Override
2236            public List<LayoutSetBranch> findByG_P_M(long groupId,
2237                    boolean privateLayout, boolean master, int start, int end) {
2238                    return findByG_P_M(groupId, privateLayout, master, start, end, null);
2239            }
2240    
2241            /**
2242             * Returns an ordered range of all the layout set branchs where groupId = &#63; and privateLayout = &#63; and master = &#63;.
2243             *
2244             * <p>
2245             * 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 LayoutSetBranchModelImpl}. 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.
2246             * </p>
2247             *
2248             * @param groupId the group ID
2249             * @param privateLayout the private layout
2250             * @param master the master
2251             * @param start the lower bound of the range of layout set branchs
2252             * @param end the upper bound of the range of layout set branchs (not inclusive)
2253             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2254             * @return the ordered range of matching layout set branchs
2255             */
2256            @Override
2257            public List<LayoutSetBranch> findByG_P_M(long groupId,
2258                    boolean privateLayout, boolean master, int start, int end,
2259                    OrderByComparator<LayoutSetBranch> orderByComparator) {
2260                    return findByG_P_M(groupId, privateLayout, master, start, end,
2261                            orderByComparator, true);
2262            }
2263    
2264            /**
2265             * Returns an ordered range of all the layout set branchs where groupId = &#63; and privateLayout = &#63; and master = &#63;.
2266             *
2267             * <p>
2268             * 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 LayoutSetBranchModelImpl}. 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.
2269             * </p>
2270             *
2271             * @param groupId the group ID
2272             * @param privateLayout the private layout
2273             * @param master the master
2274             * @param start the lower bound of the range of layout set branchs
2275             * @param end the upper bound of the range of layout set branchs (not inclusive)
2276             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2277             * @param retrieveFromCache whether to retrieve from the finder cache
2278             * @return the ordered range of matching layout set branchs
2279             */
2280            @Override
2281            public List<LayoutSetBranch> findByG_P_M(long groupId,
2282                    boolean privateLayout, boolean master, int start, int end,
2283                    OrderByComparator<LayoutSetBranch> orderByComparator,
2284                    boolean retrieveFromCache) {
2285                    boolean pagination = true;
2286                    FinderPath finderPath = null;
2287                    Object[] finderArgs = null;
2288    
2289                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2290                                    (orderByComparator == null)) {
2291                            pagination = false;
2292                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_M;
2293                            finderArgs = new Object[] { groupId, privateLayout, master };
2294                    }
2295                    else {
2296                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_M;
2297                            finderArgs = new Object[] {
2298                                            groupId, privateLayout, master,
2299                                            
2300                                            start, end, orderByComparator
2301                                    };
2302                    }
2303    
2304                    List<LayoutSetBranch> list = null;
2305    
2306                    if (retrieveFromCache) {
2307                            list = (List<LayoutSetBranch>)finderCache.getResult(finderPath,
2308                                            finderArgs, this);
2309    
2310                            if ((list != null) && !list.isEmpty()) {
2311                                    for (LayoutSetBranch layoutSetBranch : list) {
2312                                            if ((groupId != layoutSetBranch.getGroupId()) ||
2313                                                            (privateLayout != layoutSetBranch.getPrivateLayout()) ||
2314                                                            (master != layoutSetBranch.getMaster())) {
2315                                                    list = null;
2316    
2317                                                    break;
2318                                            }
2319                                    }
2320                            }
2321                    }
2322    
2323                    if (list == null) {
2324                            StringBundler query = null;
2325    
2326                            if (orderByComparator != null) {
2327                                    query = new StringBundler(5 +
2328                                                    (orderByComparator.getOrderByFields().length * 2));
2329                            }
2330                            else {
2331                                    query = new StringBundler(5);
2332                            }
2333    
2334                            query.append(_SQL_SELECT_LAYOUTSETBRANCH_WHERE);
2335    
2336                            query.append(_FINDER_COLUMN_G_P_M_GROUPID_2);
2337    
2338                            query.append(_FINDER_COLUMN_G_P_M_PRIVATELAYOUT_2);
2339    
2340                            query.append(_FINDER_COLUMN_G_P_M_MASTER_2);
2341    
2342                            if (orderByComparator != null) {
2343                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2344                                            orderByComparator);
2345                            }
2346                            else
2347                             if (pagination) {
2348                                    query.append(LayoutSetBranchModelImpl.ORDER_BY_JPQL);
2349                            }
2350    
2351                            String sql = query.toString();
2352    
2353                            Session session = null;
2354    
2355                            try {
2356                                    session = openSession();
2357    
2358                                    Query q = session.createQuery(sql);
2359    
2360                                    QueryPos qPos = QueryPos.getInstance(q);
2361    
2362                                    qPos.add(groupId);
2363    
2364                                    qPos.add(privateLayout);
2365    
2366                                    qPos.add(master);
2367    
2368                                    if (!pagination) {
2369                                            list = (List<LayoutSetBranch>)QueryUtil.list(q,
2370                                                            getDialect(), start, end, false);
2371    
2372                                            Collections.sort(list);
2373    
2374                                            list = Collections.unmodifiableList(list);
2375                                    }
2376                                    else {
2377                                            list = (List<LayoutSetBranch>)QueryUtil.list(q,
2378                                                            getDialect(), start, end);
2379                                    }
2380    
2381                                    cacheResult(list);
2382    
2383                                    finderCache.putResult(finderPath, finderArgs, list);
2384                            }
2385                            catch (Exception e) {
2386                                    finderCache.removeResult(finderPath, finderArgs);
2387    
2388                                    throw processException(e);
2389                            }
2390                            finally {
2391                                    closeSession(session);
2392                            }
2393                    }
2394    
2395                    return list;
2396            }
2397    
2398            /**
2399             * Returns the first layout set branch in the ordered set where groupId = &#63; and privateLayout = &#63; and master = &#63;.
2400             *
2401             * @param groupId the group ID
2402             * @param privateLayout the private layout
2403             * @param master the master
2404             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2405             * @return the first matching layout set branch
2406             * @throws NoSuchLayoutSetBranchException if a matching layout set branch could not be found
2407             */
2408            @Override
2409            public LayoutSetBranch findByG_P_M_First(long groupId,
2410                    boolean privateLayout, boolean master,
2411                    OrderByComparator<LayoutSetBranch> orderByComparator)
2412                    throws NoSuchLayoutSetBranchException {
2413                    LayoutSetBranch layoutSetBranch = fetchByG_P_M_First(groupId,
2414                                    privateLayout, master, orderByComparator);
2415    
2416                    if (layoutSetBranch != null) {
2417                            return layoutSetBranch;
2418                    }
2419    
2420                    StringBundler msg = new StringBundler(8);
2421    
2422                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2423    
2424                    msg.append("groupId=");
2425                    msg.append(groupId);
2426    
2427                    msg.append(", privateLayout=");
2428                    msg.append(privateLayout);
2429    
2430                    msg.append(", master=");
2431                    msg.append(master);
2432    
2433                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2434    
2435                    throw new NoSuchLayoutSetBranchException(msg.toString());
2436            }
2437    
2438            /**
2439             * Returns the first layout set branch in the ordered set where groupId = &#63; and privateLayout = &#63; and master = &#63;.
2440             *
2441             * @param groupId the group ID
2442             * @param privateLayout the private layout
2443             * @param master the master
2444             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2445             * @return the first matching layout set branch, or <code>null</code> if a matching layout set branch could not be found
2446             */
2447            @Override
2448            public LayoutSetBranch fetchByG_P_M_First(long groupId,
2449                    boolean privateLayout, boolean master,
2450                    OrderByComparator<LayoutSetBranch> orderByComparator) {
2451                    List<LayoutSetBranch> list = findByG_P_M(groupId, privateLayout,
2452                                    master, 0, 1, orderByComparator);
2453    
2454                    if (!list.isEmpty()) {
2455                            return list.get(0);
2456                    }
2457    
2458                    return null;
2459            }
2460    
2461            /**
2462             * Returns the last layout set branch in the ordered set where groupId = &#63; and privateLayout = &#63; and master = &#63;.
2463             *
2464             * @param groupId the group ID
2465             * @param privateLayout the private layout
2466             * @param master the master
2467             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2468             * @return the last matching layout set branch
2469             * @throws NoSuchLayoutSetBranchException if a matching layout set branch could not be found
2470             */
2471            @Override
2472            public LayoutSetBranch findByG_P_M_Last(long groupId,
2473                    boolean privateLayout, boolean master,
2474                    OrderByComparator<LayoutSetBranch> orderByComparator)
2475                    throws NoSuchLayoutSetBranchException {
2476                    LayoutSetBranch layoutSetBranch = fetchByG_P_M_Last(groupId,
2477                                    privateLayout, master, orderByComparator);
2478    
2479                    if (layoutSetBranch != null) {
2480                            return layoutSetBranch;
2481                    }
2482    
2483                    StringBundler msg = new StringBundler(8);
2484    
2485                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2486    
2487                    msg.append("groupId=");
2488                    msg.append(groupId);
2489    
2490                    msg.append(", privateLayout=");
2491                    msg.append(privateLayout);
2492    
2493                    msg.append(", master=");
2494                    msg.append(master);
2495    
2496                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2497    
2498                    throw new NoSuchLayoutSetBranchException(msg.toString());
2499            }
2500    
2501            /**
2502             * Returns the last layout set branch in the ordered set where groupId = &#63; and privateLayout = &#63; and master = &#63;.
2503             *
2504             * @param groupId the group ID
2505             * @param privateLayout the private layout
2506             * @param master the master
2507             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2508             * @return the last matching layout set branch, or <code>null</code> if a matching layout set branch could not be found
2509             */
2510            @Override
2511            public LayoutSetBranch fetchByG_P_M_Last(long groupId,
2512                    boolean privateLayout, boolean master,
2513                    OrderByComparator<LayoutSetBranch> orderByComparator) {
2514                    int count = countByG_P_M(groupId, privateLayout, master);
2515    
2516                    if (count == 0) {
2517                            return null;
2518                    }
2519    
2520                    List<LayoutSetBranch> list = findByG_P_M(groupId, privateLayout,
2521                                    master, count - 1, count, orderByComparator);
2522    
2523                    if (!list.isEmpty()) {
2524                            return list.get(0);
2525                    }
2526    
2527                    return null;
2528            }
2529    
2530            /**
2531             * Returns the layout set branchs before and after the current layout set branch in the ordered set where groupId = &#63; and privateLayout = &#63; and master = &#63;.
2532             *
2533             * @param layoutSetBranchId the primary key of the current layout set branch
2534             * @param groupId the group ID
2535             * @param privateLayout the private layout
2536             * @param master the master
2537             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2538             * @return the previous, current, and next layout set branch
2539             * @throws NoSuchLayoutSetBranchException if a layout set branch with the primary key could not be found
2540             */
2541            @Override
2542            public LayoutSetBranch[] findByG_P_M_PrevAndNext(long layoutSetBranchId,
2543                    long groupId, boolean privateLayout, boolean master,
2544                    OrderByComparator<LayoutSetBranch> orderByComparator)
2545                    throws NoSuchLayoutSetBranchException {
2546                    LayoutSetBranch layoutSetBranch = findByPrimaryKey(layoutSetBranchId);
2547    
2548                    Session session = null;
2549    
2550                    try {
2551                            session = openSession();
2552    
2553                            LayoutSetBranch[] array = new LayoutSetBranchImpl[3];
2554    
2555                            array[0] = getByG_P_M_PrevAndNext(session, layoutSetBranch,
2556                                            groupId, privateLayout, master, orderByComparator, true);
2557    
2558                            array[1] = layoutSetBranch;
2559    
2560                            array[2] = getByG_P_M_PrevAndNext(session, layoutSetBranch,
2561                                            groupId, privateLayout, master, orderByComparator, false);
2562    
2563                            return array;
2564                    }
2565                    catch (Exception e) {
2566                            throw processException(e);
2567                    }
2568                    finally {
2569                            closeSession(session);
2570                    }
2571            }
2572    
2573            protected LayoutSetBranch getByG_P_M_PrevAndNext(Session session,
2574                    LayoutSetBranch layoutSetBranch, long groupId, boolean privateLayout,
2575                    boolean master, OrderByComparator<LayoutSetBranch> orderByComparator,
2576                    boolean previous) {
2577                    StringBundler query = null;
2578    
2579                    if (orderByComparator != null) {
2580                            query = new StringBundler(6 +
2581                                            (orderByComparator.getOrderByConditionFields().length * 3) +
2582                                            (orderByComparator.getOrderByFields().length * 3));
2583                    }
2584                    else {
2585                            query = new StringBundler(5);
2586                    }
2587    
2588                    query.append(_SQL_SELECT_LAYOUTSETBRANCH_WHERE);
2589    
2590                    query.append(_FINDER_COLUMN_G_P_M_GROUPID_2);
2591    
2592                    query.append(_FINDER_COLUMN_G_P_M_PRIVATELAYOUT_2);
2593    
2594                    query.append(_FINDER_COLUMN_G_P_M_MASTER_2);
2595    
2596                    if (orderByComparator != null) {
2597                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2598    
2599                            if (orderByConditionFields.length > 0) {
2600                                    query.append(WHERE_AND);
2601                            }
2602    
2603                            for (int i = 0; i < orderByConditionFields.length; i++) {
2604                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2605                                    query.append(orderByConditionFields[i]);
2606    
2607                                    if ((i + 1) < orderByConditionFields.length) {
2608                                            if (orderByComparator.isAscending() ^ previous) {
2609                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2610                                            }
2611                                            else {
2612                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2613                                            }
2614                                    }
2615                                    else {
2616                                            if (orderByComparator.isAscending() ^ previous) {
2617                                                    query.append(WHERE_GREATER_THAN);
2618                                            }
2619                                            else {
2620                                                    query.append(WHERE_LESSER_THAN);
2621                                            }
2622                                    }
2623                            }
2624    
2625                            query.append(ORDER_BY_CLAUSE);
2626    
2627                            String[] orderByFields = orderByComparator.getOrderByFields();
2628    
2629                            for (int i = 0; i < orderByFields.length; i++) {
2630                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2631                                    query.append(orderByFields[i]);
2632    
2633                                    if ((i + 1) < orderByFields.length) {
2634                                            if (orderByComparator.isAscending() ^ previous) {
2635                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2636                                            }
2637                                            else {
2638                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2639                                            }
2640                                    }
2641                                    else {
2642                                            if (orderByComparator.isAscending() ^ previous) {
2643                                                    query.append(ORDER_BY_ASC);
2644                                            }
2645                                            else {
2646                                                    query.append(ORDER_BY_DESC);
2647                                            }
2648                                    }
2649                            }
2650                    }
2651                    else {
2652                            query.append(LayoutSetBranchModelImpl.ORDER_BY_JPQL);
2653                    }
2654    
2655                    String sql = query.toString();
2656    
2657                    Query q = session.createQuery(sql);
2658    
2659                    q.setFirstResult(0);
2660                    q.setMaxResults(2);
2661    
2662                    QueryPos qPos = QueryPos.getInstance(q);
2663    
2664                    qPos.add(groupId);
2665    
2666                    qPos.add(privateLayout);
2667    
2668                    qPos.add(master);
2669    
2670                    if (orderByComparator != null) {
2671                            Object[] values = orderByComparator.getOrderByConditionValues(layoutSetBranch);
2672    
2673                            for (Object value : values) {
2674                                    qPos.add(value);
2675                            }
2676                    }
2677    
2678                    List<LayoutSetBranch> list = q.list();
2679    
2680                    if (list.size() == 2) {
2681                            return list.get(1);
2682                    }
2683                    else {
2684                            return null;
2685                    }
2686            }
2687    
2688            /**
2689             * Returns all the layout set branchs that the user has permission to view where groupId = &#63; and privateLayout = &#63; and master = &#63;.
2690             *
2691             * @param groupId the group ID
2692             * @param privateLayout the private layout
2693             * @param master the master
2694             * @return the matching layout set branchs that the user has permission to view
2695             */
2696            @Override
2697            public List<LayoutSetBranch> filterFindByG_P_M(long groupId,
2698                    boolean privateLayout, boolean master) {
2699                    return filterFindByG_P_M(groupId, privateLayout, master,
2700                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2701            }
2702    
2703            /**
2704             * Returns a range of all the layout set branchs that the user has permission to view where groupId = &#63; and privateLayout = &#63; and master = &#63;.
2705             *
2706             * <p>
2707             * 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 LayoutSetBranchModelImpl}. 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.
2708             * </p>
2709             *
2710             * @param groupId the group ID
2711             * @param privateLayout the private layout
2712             * @param master the master
2713             * @param start the lower bound of the range of layout set branchs
2714             * @param end the upper bound of the range of layout set branchs (not inclusive)
2715             * @return the range of matching layout set branchs that the user has permission to view
2716             */
2717            @Override
2718            public List<LayoutSetBranch> filterFindByG_P_M(long groupId,
2719                    boolean privateLayout, boolean master, int start, int end) {
2720                    return filterFindByG_P_M(groupId, privateLayout, master, start, end,
2721                            null);
2722            }
2723    
2724            /**
2725             * Returns an ordered range of all the layout set branchs that the user has permissions to view where groupId = &#63; and privateLayout = &#63; and master = &#63;.
2726             *
2727             * <p>
2728             * 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 LayoutSetBranchModelImpl}. 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.
2729             * </p>
2730             *
2731             * @param groupId the group ID
2732             * @param privateLayout the private layout
2733             * @param master the master
2734             * @param start the lower bound of the range of layout set branchs
2735             * @param end the upper bound of the range of layout set branchs (not inclusive)
2736             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2737             * @return the ordered range of matching layout set branchs that the user has permission to view
2738             */
2739            @Override
2740            public List<LayoutSetBranch> filterFindByG_P_M(long groupId,
2741                    boolean privateLayout, boolean master, int start, int end,
2742                    OrderByComparator<LayoutSetBranch> orderByComparator) {
2743                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2744                            return findByG_P_M(groupId, privateLayout, master, start, end,
2745                                    orderByComparator);
2746                    }
2747    
2748                    StringBundler query = null;
2749    
2750                    if (orderByComparator != null) {
2751                            query = new StringBundler(5 +
2752                                            (orderByComparator.getOrderByFields().length * 2));
2753                    }
2754                    else {
2755                            query = new StringBundler(6);
2756                    }
2757    
2758                    if (getDB().isSupportsInlineDistinct()) {
2759                            query.append(_FILTER_SQL_SELECT_LAYOUTSETBRANCH_WHERE);
2760                    }
2761                    else {
2762                            query.append(_FILTER_SQL_SELECT_LAYOUTSETBRANCH_NO_INLINE_DISTINCT_WHERE_1);
2763                    }
2764    
2765                    query.append(_FINDER_COLUMN_G_P_M_GROUPID_2);
2766    
2767                    query.append(_FINDER_COLUMN_G_P_M_PRIVATELAYOUT_2);
2768    
2769                    query.append(_FINDER_COLUMN_G_P_M_MASTER_2);
2770    
2771                    if (!getDB().isSupportsInlineDistinct()) {
2772                            query.append(_FILTER_SQL_SELECT_LAYOUTSETBRANCH_NO_INLINE_DISTINCT_WHERE_2);
2773                    }
2774    
2775                    if (orderByComparator != null) {
2776                            if (getDB().isSupportsInlineDistinct()) {
2777                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2778                                            orderByComparator, true);
2779                            }
2780                            else {
2781                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2782                                            orderByComparator, true);
2783                            }
2784                    }
2785                    else {
2786                            if (getDB().isSupportsInlineDistinct()) {
2787                                    query.append(LayoutSetBranchModelImpl.ORDER_BY_JPQL);
2788                            }
2789                            else {
2790                                    query.append(LayoutSetBranchModelImpl.ORDER_BY_SQL);
2791                            }
2792                    }
2793    
2794                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2795                                    LayoutSetBranch.class.getName(),
2796                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2797    
2798                    Session session = null;
2799    
2800                    try {
2801                            session = openSession();
2802    
2803                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
2804    
2805                            if (getDB().isSupportsInlineDistinct()) {
2806                                    q.addEntity(_FILTER_ENTITY_ALIAS, LayoutSetBranchImpl.class);
2807                            }
2808                            else {
2809                                    q.addEntity(_FILTER_ENTITY_TABLE, LayoutSetBranchImpl.class);
2810                            }
2811    
2812                            QueryPos qPos = QueryPos.getInstance(q);
2813    
2814                            qPos.add(groupId);
2815    
2816                            qPos.add(privateLayout);
2817    
2818                            qPos.add(master);
2819    
2820                            return (List<LayoutSetBranch>)QueryUtil.list(q, getDialect(),
2821                                    start, end);
2822                    }
2823                    catch (Exception e) {
2824                            throw processException(e);
2825                    }
2826                    finally {
2827                            closeSession(session);
2828                    }
2829            }
2830    
2831            /**
2832             * Returns the layout set branchs before and after the current layout set branch in the ordered set of layout set branchs that the user has permission to view where groupId = &#63; and privateLayout = &#63; and master = &#63;.
2833             *
2834             * @param layoutSetBranchId the primary key of the current layout set branch
2835             * @param groupId the group ID
2836             * @param privateLayout the private layout
2837             * @param master the master
2838             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2839             * @return the previous, current, and next layout set branch
2840             * @throws NoSuchLayoutSetBranchException if a layout set branch with the primary key could not be found
2841             */
2842            @Override
2843            public LayoutSetBranch[] filterFindByG_P_M_PrevAndNext(
2844                    long layoutSetBranchId, long groupId, boolean privateLayout,
2845                    boolean master, OrderByComparator<LayoutSetBranch> orderByComparator)
2846                    throws NoSuchLayoutSetBranchException {
2847                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2848                            return findByG_P_M_PrevAndNext(layoutSetBranchId, groupId,
2849                                    privateLayout, master, orderByComparator);
2850                    }
2851    
2852                    LayoutSetBranch layoutSetBranch = findByPrimaryKey(layoutSetBranchId);
2853    
2854                    Session session = null;
2855    
2856                    try {
2857                            session = openSession();
2858    
2859                            LayoutSetBranch[] array = new LayoutSetBranchImpl[3];
2860    
2861                            array[0] = filterGetByG_P_M_PrevAndNext(session, layoutSetBranch,
2862                                            groupId, privateLayout, master, orderByComparator, true);
2863    
2864                            array[1] = layoutSetBranch;
2865    
2866                            array[2] = filterGetByG_P_M_PrevAndNext(session, layoutSetBranch,
2867                                            groupId, privateLayout, master, orderByComparator, false);
2868    
2869                            return array;
2870                    }
2871                    catch (Exception e) {
2872                            throw processException(e);
2873                    }
2874                    finally {
2875                            closeSession(session);
2876                    }
2877            }
2878    
2879            protected LayoutSetBranch filterGetByG_P_M_PrevAndNext(Session session,
2880                    LayoutSetBranch layoutSetBranch, long groupId, boolean privateLayout,
2881                    boolean master, OrderByComparator<LayoutSetBranch> orderByComparator,
2882                    boolean previous) {
2883                    StringBundler query = null;
2884    
2885                    if (orderByComparator != null) {
2886                            query = new StringBundler(7 +
2887                                            (orderByComparator.getOrderByConditionFields().length * 3) +
2888                                            (orderByComparator.getOrderByFields().length * 3));
2889                    }
2890                    else {
2891                            query = new StringBundler(6);
2892                    }
2893    
2894                    if (getDB().isSupportsInlineDistinct()) {
2895                            query.append(_FILTER_SQL_SELECT_LAYOUTSETBRANCH_WHERE);
2896                    }
2897                    else {
2898                            query.append(_FILTER_SQL_SELECT_LAYOUTSETBRANCH_NO_INLINE_DISTINCT_WHERE_1);
2899                    }
2900    
2901                    query.append(_FINDER_COLUMN_G_P_M_GROUPID_2);
2902    
2903                    query.append(_FINDER_COLUMN_G_P_M_PRIVATELAYOUT_2);
2904    
2905                    query.append(_FINDER_COLUMN_G_P_M_MASTER_2);
2906    
2907                    if (!getDB().isSupportsInlineDistinct()) {
2908                            query.append(_FILTER_SQL_SELECT_LAYOUTSETBRANCH_NO_INLINE_DISTINCT_WHERE_2);
2909                    }
2910    
2911                    if (orderByComparator != null) {
2912                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2913    
2914                            if (orderByConditionFields.length > 0) {
2915                                    query.append(WHERE_AND);
2916                            }
2917    
2918                            for (int i = 0; i < orderByConditionFields.length; i++) {
2919                                    if (getDB().isSupportsInlineDistinct()) {
2920                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2921                                    }
2922                                    else {
2923                                            query.append(_ORDER_BY_ENTITY_TABLE);
2924                                    }
2925    
2926                                    query.append(orderByConditionFields[i]);
2927    
2928                                    if ((i + 1) < orderByConditionFields.length) {
2929                                            if (orderByComparator.isAscending() ^ previous) {
2930                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2931                                            }
2932                                            else {
2933                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2934                                            }
2935                                    }
2936                                    else {
2937                                            if (orderByComparator.isAscending() ^ previous) {
2938                                                    query.append(WHERE_GREATER_THAN);
2939                                            }
2940                                            else {
2941                                                    query.append(WHERE_LESSER_THAN);
2942                                            }
2943                                    }
2944                            }
2945    
2946                            query.append(ORDER_BY_CLAUSE);
2947    
2948                            String[] orderByFields = orderByComparator.getOrderByFields();
2949    
2950                            for (int i = 0; i < orderByFields.length; i++) {
2951                                    if (getDB().isSupportsInlineDistinct()) {
2952                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2953                                    }
2954                                    else {
2955                                            query.append(_ORDER_BY_ENTITY_TABLE);
2956                                    }
2957    
2958                                    query.append(orderByFields[i]);
2959    
2960                                    if ((i + 1) < orderByFields.length) {
2961                                            if (orderByComparator.isAscending() ^ previous) {
2962                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2963                                            }
2964                                            else {
2965                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2966                                            }
2967                                    }
2968                                    else {
2969                                            if (orderByComparator.isAscending() ^ previous) {
2970                                                    query.append(ORDER_BY_ASC);
2971                                            }
2972                                            else {
2973                                                    query.append(ORDER_BY_DESC);
2974                                            }
2975                                    }
2976                            }
2977                    }
2978                    else {
2979                            if (getDB().isSupportsInlineDistinct()) {
2980                                    query.append(LayoutSetBranchModelImpl.ORDER_BY_JPQL);
2981                            }
2982                            else {
2983                                    query.append(LayoutSetBranchModelImpl.ORDER_BY_SQL);
2984                            }
2985                    }
2986    
2987                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2988                                    LayoutSetBranch.class.getName(),
2989                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2990    
2991                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
2992    
2993                    q.setFirstResult(0);
2994                    q.setMaxResults(2);
2995    
2996                    if (getDB().isSupportsInlineDistinct()) {
2997                            q.addEntity(_FILTER_ENTITY_ALIAS, LayoutSetBranchImpl.class);
2998                    }
2999                    else {
3000                            q.addEntity(_FILTER_ENTITY_TABLE, LayoutSetBranchImpl.class);
3001                    }
3002    
3003                    QueryPos qPos = QueryPos.getInstance(q);
3004    
3005                    qPos.add(groupId);
3006    
3007                    qPos.add(privateLayout);
3008    
3009                    qPos.add(master);
3010    
3011                    if (orderByComparator != null) {
3012                            Object[] values = orderByComparator.getOrderByConditionValues(layoutSetBranch);
3013    
3014                            for (Object value : values) {
3015                                    qPos.add(value);
3016                            }
3017                    }
3018    
3019                    List<LayoutSetBranch> list = q.list();
3020    
3021                    if (list.size() == 2) {
3022                            return list.get(1);
3023                    }
3024                    else {
3025                            return null;
3026                    }
3027            }
3028    
3029            /**
3030             * Removes all the layout set branchs where groupId = &#63; and privateLayout = &#63; and master = &#63; from the database.
3031             *
3032             * @param groupId the group ID
3033             * @param privateLayout the private layout
3034             * @param master the master
3035             */
3036            @Override
3037            public void removeByG_P_M(long groupId, boolean privateLayout,
3038                    boolean master) {
3039                    for (LayoutSetBranch layoutSetBranch : findByG_P_M(groupId,
3040                                    privateLayout, master, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
3041                                    null)) {
3042                            remove(layoutSetBranch);
3043                    }
3044            }
3045    
3046            /**
3047             * Returns the number of layout set branchs where groupId = &#63; and privateLayout = &#63; and master = &#63;.
3048             *
3049             * @param groupId the group ID
3050             * @param privateLayout the private layout
3051             * @param master the master
3052             * @return the number of matching layout set branchs
3053             */
3054            @Override
3055            public int countByG_P_M(long groupId, boolean privateLayout, boolean master) {
3056                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_P_M;
3057    
3058                    Object[] finderArgs = new Object[] { groupId, privateLayout, master };
3059    
3060                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
3061    
3062                    if (count == null) {
3063                            StringBundler query = new StringBundler(4);
3064    
3065                            query.append(_SQL_COUNT_LAYOUTSETBRANCH_WHERE);
3066    
3067                            query.append(_FINDER_COLUMN_G_P_M_GROUPID_2);
3068    
3069                            query.append(_FINDER_COLUMN_G_P_M_PRIVATELAYOUT_2);
3070    
3071                            query.append(_FINDER_COLUMN_G_P_M_MASTER_2);
3072    
3073                            String sql = query.toString();
3074    
3075                            Session session = null;
3076    
3077                            try {
3078                                    session = openSession();
3079    
3080                                    Query q = session.createQuery(sql);
3081    
3082                                    QueryPos qPos = QueryPos.getInstance(q);
3083    
3084                                    qPos.add(groupId);
3085    
3086                                    qPos.add(privateLayout);
3087    
3088                                    qPos.add(master);
3089    
3090                                    count = (Long)q.uniqueResult();
3091    
3092                                    finderCache.putResult(finderPath, finderArgs, count);
3093                            }
3094                            catch (Exception e) {
3095                                    finderCache.removeResult(finderPath, finderArgs);
3096    
3097                                    throw processException(e);
3098                            }
3099                            finally {
3100                                    closeSession(session);
3101                            }
3102                    }
3103    
3104                    return count.intValue();
3105            }
3106    
3107            /**
3108             * Returns the number of layout set branchs that the user has permission to view where groupId = &#63; and privateLayout = &#63; and master = &#63;.
3109             *
3110             * @param groupId the group ID
3111             * @param privateLayout the private layout
3112             * @param master the master
3113             * @return the number of matching layout set branchs that the user has permission to view
3114             */
3115            @Override
3116            public int filterCountByG_P_M(long groupId, boolean privateLayout,
3117                    boolean master) {
3118                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3119                            return countByG_P_M(groupId, privateLayout, master);
3120                    }
3121    
3122                    StringBundler query = new StringBundler(4);
3123    
3124                    query.append(_FILTER_SQL_COUNT_LAYOUTSETBRANCH_WHERE);
3125    
3126                    query.append(_FINDER_COLUMN_G_P_M_GROUPID_2);
3127    
3128                    query.append(_FINDER_COLUMN_G_P_M_PRIVATELAYOUT_2);
3129    
3130                    query.append(_FINDER_COLUMN_G_P_M_MASTER_2);
3131    
3132                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3133                                    LayoutSetBranch.class.getName(),
3134                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3135    
3136                    Session session = null;
3137    
3138                    try {
3139                            session = openSession();
3140    
3141                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
3142    
3143                            q.addScalar(COUNT_COLUMN_NAME,
3144                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
3145    
3146                            QueryPos qPos = QueryPos.getInstance(q);
3147    
3148                            qPos.add(groupId);
3149    
3150                            qPos.add(privateLayout);
3151    
3152                            qPos.add(master);
3153    
3154                            Long count = (Long)q.uniqueResult();
3155    
3156                            return count.intValue();
3157                    }
3158                    catch (Exception e) {
3159                            throw processException(e);
3160                    }
3161                    finally {
3162                            closeSession(session);
3163                    }
3164            }
3165    
3166            private static final String _FINDER_COLUMN_G_P_M_GROUPID_2 = "layoutSetBranch.groupId = ? AND ";
3167            private static final String _FINDER_COLUMN_G_P_M_PRIVATELAYOUT_2 = "layoutSetBranch.privateLayout = ? AND ";
3168            private static final String _FINDER_COLUMN_G_P_M_MASTER_2 = "layoutSetBranch.master = ?";
3169    
3170            public LayoutSetBranchPersistenceImpl() {
3171                    setModelClass(LayoutSetBranch.class);
3172            }
3173    
3174            /**
3175             * Caches the layout set branch in the entity cache if it is enabled.
3176             *
3177             * @param layoutSetBranch the layout set branch
3178             */
3179            @Override
3180            public void cacheResult(LayoutSetBranch layoutSetBranch) {
3181                    entityCache.putResult(LayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
3182                            LayoutSetBranchImpl.class, layoutSetBranch.getPrimaryKey(),
3183                            layoutSetBranch);
3184    
3185                    finderCache.putResult(FINDER_PATH_FETCH_BY_G_P_N,
3186                            new Object[] {
3187                                    layoutSetBranch.getGroupId(), layoutSetBranch.getPrivateLayout(),
3188                                    layoutSetBranch.getName()
3189                            }, layoutSetBranch);
3190    
3191                    layoutSetBranch.resetOriginalValues();
3192            }
3193    
3194            /**
3195             * Caches the layout set branchs in the entity cache if it is enabled.
3196             *
3197             * @param layoutSetBranchs the layout set branchs
3198             */
3199            @Override
3200            public void cacheResult(List<LayoutSetBranch> layoutSetBranchs) {
3201                    for (LayoutSetBranch layoutSetBranch : layoutSetBranchs) {
3202                            if (entityCache.getResult(
3203                                                    LayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
3204                                                    LayoutSetBranchImpl.class,
3205                                                    layoutSetBranch.getPrimaryKey()) == null) {
3206                                    cacheResult(layoutSetBranch);
3207                            }
3208                            else {
3209                                    layoutSetBranch.resetOriginalValues();
3210                            }
3211                    }
3212            }
3213    
3214            /**
3215             * Clears the cache for all layout set branchs.
3216             *
3217             * <p>
3218             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
3219             * </p>
3220             */
3221            @Override
3222            public void clearCache() {
3223                    entityCache.clearCache(LayoutSetBranchImpl.class);
3224    
3225                    finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
3226                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3227                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3228            }
3229    
3230            /**
3231             * Clears the cache for the layout set branch.
3232             *
3233             * <p>
3234             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
3235             * </p>
3236             */
3237            @Override
3238            public void clearCache(LayoutSetBranch layoutSetBranch) {
3239                    entityCache.removeResult(LayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
3240                            LayoutSetBranchImpl.class, layoutSetBranch.getPrimaryKey());
3241    
3242                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3243                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3244    
3245                    clearUniqueFindersCache((LayoutSetBranchModelImpl)layoutSetBranch);
3246            }
3247    
3248            @Override
3249            public void clearCache(List<LayoutSetBranch> layoutSetBranchs) {
3250                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3251                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3252    
3253                    for (LayoutSetBranch layoutSetBranch : layoutSetBranchs) {
3254                            entityCache.removeResult(LayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
3255                                    LayoutSetBranchImpl.class, layoutSetBranch.getPrimaryKey());
3256    
3257                            clearUniqueFindersCache((LayoutSetBranchModelImpl)layoutSetBranch);
3258                    }
3259            }
3260    
3261            protected void cacheUniqueFindersCache(
3262                    LayoutSetBranchModelImpl layoutSetBranchModelImpl, boolean isNew) {
3263                    if (isNew) {
3264                            Object[] args = new Object[] {
3265                                            layoutSetBranchModelImpl.getGroupId(),
3266                                            layoutSetBranchModelImpl.getPrivateLayout(),
3267                                            layoutSetBranchModelImpl.getName()
3268                                    };
3269    
3270                            finderCache.putResult(FINDER_PATH_COUNT_BY_G_P_N, args,
3271                                    Long.valueOf(1));
3272                            finderCache.putResult(FINDER_PATH_FETCH_BY_G_P_N, args,
3273                                    layoutSetBranchModelImpl);
3274                    }
3275                    else {
3276                            if ((layoutSetBranchModelImpl.getColumnBitmask() &
3277                                            FINDER_PATH_FETCH_BY_G_P_N.getColumnBitmask()) != 0) {
3278                                    Object[] args = new Object[] {
3279                                                    layoutSetBranchModelImpl.getGroupId(),
3280                                                    layoutSetBranchModelImpl.getPrivateLayout(),
3281                                                    layoutSetBranchModelImpl.getName()
3282                                            };
3283    
3284                                    finderCache.putResult(FINDER_PATH_COUNT_BY_G_P_N, args,
3285                                            Long.valueOf(1));
3286                                    finderCache.putResult(FINDER_PATH_FETCH_BY_G_P_N, args,
3287                                            layoutSetBranchModelImpl);
3288                            }
3289                    }
3290            }
3291    
3292            protected void clearUniqueFindersCache(
3293                    LayoutSetBranchModelImpl layoutSetBranchModelImpl) {
3294                    Object[] args = new Object[] {
3295                                    layoutSetBranchModelImpl.getGroupId(),
3296                                    layoutSetBranchModelImpl.getPrivateLayout(),
3297                                    layoutSetBranchModelImpl.getName()
3298                            };
3299    
3300                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_P_N, args);
3301                    finderCache.removeResult(FINDER_PATH_FETCH_BY_G_P_N, args);
3302    
3303                    if ((layoutSetBranchModelImpl.getColumnBitmask() &
3304                                    FINDER_PATH_FETCH_BY_G_P_N.getColumnBitmask()) != 0) {
3305                            args = new Object[] {
3306                                            layoutSetBranchModelImpl.getOriginalGroupId(),
3307                                            layoutSetBranchModelImpl.getOriginalPrivateLayout(),
3308                                            layoutSetBranchModelImpl.getOriginalName()
3309                                    };
3310    
3311                            finderCache.removeResult(FINDER_PATH_COUNT_BY_G_P_N, args);
3312                            finderCache.removeResult(FINDER_PATH_FETCH_BY_G_P_N, args);
3313                    }
3314            }
3315    
3316            /**
3317             * Creates a new layout set branch with the primary key. Does not add the layout set branch to the database.
3318             *
3319             * @param layoutSetBranchId the primary key for the new layout set branch
3320             * @return the new layout set branch
3321             */
3322            @Override
3323            public LayoutSetBranch create(long layoutSetBranchId) {
3324                    LayoutSetBranch layoutSetBranch = new LayoutSetBranchImpl();
3325    
3326                    layoutSetBranch.setNew(true);
3327                    layoutSetBranch.setPrimaryKey(layoutSetBranchId);
3328    
3329                    layoutSetBranch.setCompanyId(companyProvider.getCompanyId());
3330    
3331                    return layoutSetBranch;
3332            }
3333    
3334            /**
3335             * Removes the layout set branch with the primary key from the database. Also notifies the appropriate model listeners.
3336             *
3337             * @param layoutSetBranchId the primary key of the layout set branch
3338             * @return the layout set branch that was removed
3339             * @throws NoSuchLayoutSetBranchException if a layout set branch with the primary key could not be found
3340             */
3341            @Override
3342            public LayoutSetBranch remove(long layoutSetBranchId)
3343                    throws NoSuchLayoutSetBranchException {
3344                    return remove((Serializable)layoutSetBranchId);
3345            }
3346    
3347            /**
3348             * Removes the layout set branch with the primary key from the database. Also notifies the appropriate model listeners.
3349             *
3350             * @param primaryKey the primary key of the layout set branch
3351             * @return the layout set branch that was removed
3352             * @throws NoSuchLayoutSetBranchException if a layout set branch with the primary key could not be found
3353             */
3354            @Override
3355            public LayoutSetBranch remove(Serializable primaryKey)
3356                    throws NoSuchLayoutSetBranchException {
3357                    Session session = null;
3358    
3359                    try {
3360                            session = openSession();
3361    
3362                            LayoutSetBranch layoutSetBranch = (LayoutSetBranch)session.get(LayoutSetBranchImpl.class,
3363                                            primaryKey);
3364    
3365                            if (layoutSetBranch == null) {
3366                                    if (_log.isWarnEnabled()) {
3367                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
3368                                    }
3369    
3370                                    throw new NoSuchLayoutSetBranchException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
3371                                            primaryKey);
3372                            }
3373    
3374                            return remove(layoutSetBranch);
3375                    }
3376                    catch (NoSuchLayoutSetBranchException nsee) {
3377                            throw nsee;
3378                    }
3379                    catch (Exception e) {
3380                            throw processException(e);
3381                    }
3382                    finally {
3383                            closeSession(session);
3384                    }
3385            }
3386    
3387            @Override
3388            protected LayoutSetBranch removeImpl(LayoutSetBranch layoutSetBranch) {
3389                    layoutSetBranch = toUnwrappedModel(layoutSetBranch);
3390    
3391                    Session session = null;
3392    
3393                    try {
3394                            session = openSession();
3395    
3396                            if (!session.contains(layoutSetBranch)) {
3397                                    layoutSetBranch = (LayoutSetBranch)session.get(LayoutSetBranchImpl.class,
3398                                                    layoutSetBranch.getPrimaryKeyObj());
3399                            }
3400    
3401                            if (layoutSetBranch != null) {
3402                                    session.delete(layoutSetBranch);
3403                            }
3404                    }
3405                    catch (Exception e) {
3406                            throw processException(e);
3407                    }
3408                    finally {
3409                            closeSession(session);
3410                    }
3411    
3412                    if (layoutSetBranch != null) {
3413                            clearCache(layoutSetBranch);
3414                    }
3415    
3416                    return layoutSetBranch;
3417            }
3418    
3419            @Override
3420            public LayoutSetBranch updateImpl(LayoutSetBranch layoutSetBranch) {
3421                    layoutSetBranch = toUnwrappedModel(layoutSetBranch);
3422    
3423                    boolean isNew = layoutSetBranch.isNew();
3424    
3425                    LayoutSetBranchModelImpl layoutSetBranchModelImpl = (LayoutSetBranchModelImpl)layoutSetBranch;
3426    
3427                    ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();
3428    
3429                    Date now = new Date();
3430    
3431                    if (isNew && (layoutSetBranch.getCreateDate() == null)) {
3432                            if (serviceContext == null) {
3433                                    layoutSetBranch.setCreateDate(now);
3434                            }
3435                            else {
3436                                    layoutSetBranch.setCreateDate(serviceContext.getCreateDate(now));
3437                            }
3438                    }
3439    
3440                    if (!layoutSetBranchModelImpl.hasSetModifiedDate()) {
3441                            if (serviceContext == null) {
3442                                    layoutSetBranch.setModifiedDate(now);
3443                            }
3444                            else {
3445                                    layoutSetBranch.setModifiedDate(serviceContext.getModifiedDate(
3446                                                    now));
3447                            }
3448                    }
3449    
3450                    Session session = null;
3451    
3452                    try {
3453                            session = openSession();
3454    
3455                            if (layoutSetBranch.isNew()) {
3456                                    session.save(layoutSetBranch);
3457    
3458                                    layoutSetBranch.setNew(false);
3459                            }
3460                            else {
3461                                    layoutSetBranch = (LayoutSetBranch)session.merge(layoutSetBranch);
3462                            }
3463                    }
3464                    catch (Exception e) {
3465                            throw processException(e);
3466                    }
3467                    finally {
3468                            closeSession(session);
3469                    }
3470    
3471                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3472    
3473                    if (isNew || !LayoutSetBranchModelImpl.COLUMN_BITMASK_ENABLED) {
3474                            finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3475                    }
3476    
3477                    else {
3478                            if ((layoutSetBranchModelImpl.getColumnBitmask() &
3479                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
3480                                    Object[] args = new Object[] {
3481                                                    layoutSetBranchModelImpl.getOriginalGroupId()
3482                                            };
3483    
3484                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
3485                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
3486                                            args);
3487    
3488                                    args = new Object[] { layoutSetBranchModelImpl.getGroupId() };
3489    
3490                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
3491                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
3492                                            args);
3493                            }
3494    
3495                            if ((layoutSetBranchModelImpl.getColumnBitmask() &
3496                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P.getColumnBitmask()) != 0) {
3497                                    Object[] args = new Object[] {
3498                                                    layoutSetBranchModelImpl.getOriginalGroupId(),
3499                                                    layoutSetBranchModelImpl.getOriginalPrivateLayout()
3500                                            };
3501    
3502                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_P, args);
3503                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P,
3504                                            args);
3505    
3506                                    args = new Object[] {
3507                                                    layoutSetBranchModelImpl.getGroupId(),
3508                                                    layoutSetBranchModelImpl.getPrivateLayout()
3509                                            };
3510    
3511                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_P, args);
3512                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P,
3513                                            args);
3514                            }
3515    
3516                            if ((layoutSetBranchModelImpl.getColumnBitmask() &
3517                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_M.getColumnBitmask()) != 0) {
3518                                    Object[] args = new Object[] {
3519                                                    layoutSetBranchModelImpl.getOriginalGroupId(),
3520                                                    layoutSetBranchModelImpl.getOriginalPrivateLayout(),
3521                                                    layoutSetBranchModelImpl.getOriginalMaster()
3522                                            };
3523    
3524                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_P_M, args);
3525                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_M,
3526                                            args);
3527    
3528                                    args = new Object[] {
3529                                                    layoutSetBranchModelImpl.getGroupId(),
3530                                                    layoutSetBranchModelImpl.getPrivateLayout(),
3531                                                    layoutSetBranchModelImpl.getMaster()
3532                                            };
3533    
3534                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_P_M, args);
3535                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_M,
3536                                            args);
3537                            }
3538                    }
3539    
3540                    entityCache.putResult(LayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
3541                            LayoutSetBranchImpl.class, layoutSetBranch.getPrimaryKey(),
3542                            layoutSetBranch, false);
3543    
3544                    clearUniqueFindersCache(layoutSetBranchModelImpl);
3545                    cacheUniqueFindersCache(layoutSetBranchModelImpl, isNew);
3546    
3547                    layoutSetBranch.resetOriginalValues();
3548    
3549                    return layoutSetBranch;
3550            }
3551    
3552            protected LayoutSetBranch toUnwrappedModel(LayoutSetBranch layoutSetBranch) {
3553                    if (layoutSetBranch instanceof LayoutSetBranchImpl) {
3554                            return layoutSetBranch;
3555                    }
3556    
3557                    LayoutSetBranchImpl layoutSetBranchImpl = new LayoutSetBranchImpl();
3558    
3559                    layoutSetBranchImpl.setNew(layoutSetBranch.isNew());
3560                    layoutSetBranchImpl.setPrimaryKey(layoutSetBranch.getPrimaryKey());
3561    
3562                    layoutSetBranchImpl.setMvccVersion(layoutSetBranch.getMvccVersion());
3563                    layoutSetBranchImpl.setLayoutSetBranchId(layoutSetBranch.getLayoutSetBranchId());
3564                    layoutSetBranchImpl.setGroupId(layoutSetBranch.getGroupId());
3565                    layoutSetBranchImpl.setCompanyId(layoutSetBranch.getCompanyId());
3566                    layoutSetBranchImpl.setUserId(layoutSetBranch.getUserId());
3567                    layoutSetBranchImpl.setUserName(layoutSetBranch.getUserName());
3568                    layoutSetBranchImpl.setCreateDate(layoutSetBranch.getCreateDate());
3569                    layoutSetBranchImpl.setModifiedDate(layoutSetBranch.getModifiedDate());
3570                    layoutSetBranchImpl.setPrivateLayout(layoutSetBranch.isPrivateLayout());
3571                    layoutSetBranchImpl.setName(layoutSetBranch.getName());
3572                    layoutSetBranchImpl.setDescription(layoutSetBranch.getDescription());
3573                    layoutSetBranchImpl.setMaster(layoutSetBranch.isMaster());
3574                    layoutSetBranchImpl.setLogoId(layoutSetBranch.getLogoId());
3575                    layoutSetBranchImpl.setThemeId(layoutSetBranch.getThemeId());
3576                    layoutSetBranchImpl.setColorSchemeId(layoutSetBranch.getColorSchemeId());
3577                    layoutSetBranchImpl.setCss(layoutSetBranch.getCss());
3578                    layoutSetBranchImpl.setSettings(layoutSetBranch.getSettings());
3579                    layoutSetBranchImpl.setLayoutSetPrototypeUuid(layoutSetBranch.getLayoutSetPrototypeUuid());
3580                    layoutSetBranchImpl.setLayoutSetPrototypeLinkEnabled(layoutSetBranch.isLayoutSetPrototypeLinkEnabled());
3581    
3582                    return layoutSetBranchImpl;
3583            }
3584    
3585            /**
3586             * Returns the layout set branch with the primary key or throws a {@link com.liferay.portal.kernel.exception.NoSuchModelException} if it could not be found.
3587             *
3588             * @param primaryKey the primary key of the layout set branch
3589             * @return the layout set branch
3590             * @throws NoSuchLayoutSetBranchException if a layout set branch with the primary key could not be found
3591             */
3592            @Override
3593            public LayoutSetBranch findByPrimaryKey(Serializable primaryKey)
3594                    throws NoSuchLayoutSetBranchException {
3595                    LayoutSetBranch layoutSetBranch = fetchByPrimaryKey(primaryKey);
3596    
3597                    if (layoutSetBranch == null) {
3598                            if (_log.isWarnEnabled()) {
3599                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
3600                            }
3601    
3602                            throw new NoSuchLayoutSetBranchException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
3603                                    primaryKey);
3604                    }
3605    
3606                    return layoutSetBranch;
3607            }
3608    
3609            /**
3610             * Returns the layout set branch with the primary key or throws a {@link NoSuchLayoutSetBranchException} if it could not be found.
3611             *
3612             * @param layoutSetBranchId the primary key of the layout set branch
3613             * @return the layout set branch
3614             * @throws NoSuchLayoutSetBranchException if a layout set branch with the primary key could not be found
3615             */
3616            @Override
3617            public LayoutSetBranch findByPrimaryKey(long layoutSetBranchId)
3618                    throws NoSuchLayoutSetBranchException {
3619                    return findByPrimaryKey((Serializable)layoutSetBranchId);
3620            }
3621    
3622            /**
3623             * Returns the layout set branch with the primary key or returns <code>null</code> if it could not be found.
3624             *
3625             * @param primaryKey the primary key of the layout set branch
3626             * @return the layout set branch, or <code>null</code> if a layout set branch with the primary key could not be found
3627             */
3628            @Override
3629            public LayoutSetBranch fetchByPrimaryKey(Serializable primaryKey) {
3630                    LayoutSetBranch layoutSetBranch = (LayoutSetBranch)entityCache.getResult(LayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
3631                                    LayoutSetBranchImpl.class, primaryKey);
3632    
3633                    if (layoutSetBranch == _nullLayoutSetBranch) {
3634                            return null;
3635                    }
3636    
3637                    if (layoutSetBranch == null) {
3638                            Session session = null;
3639    
3640                            try {
3641                                    session = openSession();
3642    
3643                                    layoutSetBranch = (LayoutSetBranch)session.get(LayoutSetBranchImpl.class,
3644                                                    primaryKey);
3645    
3646                                    if (layoutSetBranch != null) {
3647                                            cacheResult(layoutSetBranch);
3648                                    }
3649                                    else {
3650                                            entityCache.putResult(LayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
3651                                                    LayoutSetBranchImpl.class, primaryKey,
3652                                                    _nullLayoutSetBranch);
3653                                    }
3654                            }
3655                            catch (Exception e) {
3656                                    entityCache.removeResult(LayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
3657                                            LayoutSetBranchImpl.class, primaryKey);
3658    
3659                                    throw processException(e);
3660                            }
3661                            finally {
3662                                    closeSession(session);
3663                            }
3664                    }
3665    
3666                    return layoutSetBranch;
3667            }
3668    
3669            /**
3670             * Returns the layout set branch with the primary key or returns <code>null</code> if it could not be found.
3671             *
3672             * @param layoutSetBranchId the primary key of the layout set branch
3673             * @return the layout set branch, or <code>null</code> if a layout set branch with the primary key could not be found
3674             */
3675            @Override
3676            public LayoutSetBranch fetchByPrimaryKey(long layoutSetBranchId) {
3677                    return fetchByPrimaryKey((Serializable)layoutSetBranchId);
3678            }
3679    
3680            @Override
3681            public Map<Serializable, LayoutSetBranch> fetchByPrimaryKeys(
3682                    Set<Serializable> primaryKeys) {
3683                    if (primaryKeys.isEmpty()) {
3684                            return Collections.emptyMap();
3685                    }
3686    
3687                    Map<Serializable, LayoutSetBranch> map = new HashMap<Serializable, LayoutSetBranch>();
3688    
3689                    if (primaryKeys.size() == 1) {
3690                            Iterator<Serializable> iterator = primaryKeys.iterator();
3691    
3692                            Serializable primaryKey = iterator.next();
3693    
3694                            LayoutSetBranch layoutSetBranch = fetchByPrimaryKey(primaryKey);
3695    
3696                            if (layoutSetBranch != null) {
3697                                    map.put(primaryKey, layoutSetBranch);
3698                            }
3699    
3700                            return map;
3701                    }
3702    
3703                    Set<Serializable> uncachedPrimaryKeys = null;
3704    
3705                    for (Serializable primaryKey : primaryKeys) {
3706                            LayoutSetBranch layoutSetBranch = (LayoutSetBranch)entityCache.getResult(LayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
3707                                            LayoutSetBranchImpl.class, primaryKey);
3708    
3709                            if (layoutSetBranch == null) {
3710                                    if (uncachedPrimaryKeys == null) {
3711                                            uncachedPrimaryKeys = new HashSet<Serializable>();
3712                                    }
3713    
3714                                    uncachedPrimaryKeys.add(primaryKey);
3715                            }
3716                            else {
3717                                    map.put(primaryKey, layoutSetBranch);
3718                            }
3719                    }
3720    
3721                    if (uncachedPrimaryKeys == null) {
3722                            return map;
3723                    }
3724    
3725                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
3726                                    1);
3727    
3728                    query.append(_SQL_SELECT_LAYOUTSETBRANCH_WHERE_PKS_IN);
3729    
3730                    for (Serializable primaryKey : uncachedPrimaryKeys) {
3731                            query.append(String.valueOf(primaryKey));
3732    
3733                            query.append(StringPool.COMMA);
3734                    }
3735    
3736                    query.setIndex(query.index() - 1);
3737    
3738                    query.append(StringPool.CLOSE_PARENTHESIS);
3739    
3740                    String sql = query.toString();
3741    
3742                    Session session = null;
3743    
3744                    try {
3745                            session = openSession();
3746    
3747                            Query q = session.createQuery(sql);
3748    
3749                            for (LayoutSetBranch layoutSetBranch : (List<LayoutSetBranch>)q.list()) {
3750                                    map.put(layoutSetBranch.getPrimaryKeyObj(), layoutSetBranch);
3751    
3752                                    cacheResult(layoutSetBranch);
3753    
3754                                    uncachedPrimaryKeys.remove(layoutSetBranch.getPrimaryKeyObj());
3755                            }
3756    
3757                            for (Serializable primaryKey : uncachedPrimaryKeys) {
3758                                    entityCache.putResult(LayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
3759                                            LayoutSetBranchImpl.class, primaryKey, _nullLayoutSetBranch);
3760                            }
3761                    }
3762                    catch (Exception e) {
3763                            throw processException(e);
3764                    }
3765                    finally {
3766                            closeSession(session);
3767                    }
3768    
3769                    return map;
3770            }
3771    
3772            /**
3773             * Returns all the layout set branchs.
3774             *
3775             * @return the layout set branchs
3776             */
3777            @Override
3778            public List<LayoutSetBranch> findAll() {
3779                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3780            }
3781    
3782            /**
3783             * Returns a range of all the layout set branchs.
3784             *
3785             * <p>
3786             * 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 LayoutSetBranchModelImpl}. 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.
3787             * </p>
3788             *
3789             * @param start the lower bound of the range of layout set branchs
3790             * @param end the upper bound of the range of layout set branchs (not inclusive)
3791             * @return the range of layout set branchs
3792             */
3793            @Override
3794            public List<LayoutSetBranch> findAll(int start, int end) {
3795                    return findAll(start, end, null);
3796            }
3797    
3798            /**
3799             * Returns an ordered range of all the layout set branchs.
3800             *
3801             * <p>
3802             * 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 LayoutSetBranchModelImpl}. 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.
3803             * </p>
3804             *
3805             * @param start the lower bound of the range of layout set branchs
3806             * @param end the upper bound of the range of layout set branchs (not inclusive)
3807             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3808             * @return the ordered range of layout set branchs
3809             */
3810            @Override
3811            public List<LayoutSetBranch> findAll(int start, int end,
3812                    OrderByComparator<LayoutSetBranch> orderByComparator) {
3813                    return findAll(start, end, orderByComparator, true);
3814            }
3815    
3816            /**
3817             * Returns an ordered range of all the layout set branchs.
3818             *
3819             * <p>
3820             * 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 LayoutSetBranchModelImpl}. 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.
3821             * </p>
3822             *
3823             * @param start the lower bound of the range of layout set branchs
3824             * @param end the upper bound of the range of layout set branchs (not inclusive)
3825             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3826             * @param retrieveFromCache whether to retrieve from the finder cache
3827             * @return the ordered range of layout set branchs
3828             */
3829            @Override
3830            public List<LayoutSetBranch> findAll(int start, int end,
3831                    OrderByComparator<LayoutSetBranch> orderByComparator,
3832                    boolean retrieveFromCache) {
3833                    boolean pagination = true;
3834                    FinderPath finderPath = null;
3835                    Object[] finderArgs = null;
3836    
3837                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3838                                    (orderByComparator == null)) {
3839                            pagination = false;
3840                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
3841                            finderArgs = FINDER_ARGS_EMPTY;
3842                    }
3843                    else {
3844                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
3845                            finderArgs = new Object[] { start, end, orderByComparator };
3846                    }
3847    
3848                    List<LayoutSetBranch> list = null;
3849    
3850                    if (retrieveFromCache) {
3851                            list = (List<LayoutSetBranch>)finderCache.getResult(finderPath,
3852                                            finderArgs, this);
3853                    }
3854    
3855                    if (list == null) {
3856                            StringBundler query = null;
3857                            String sql = null;
3858    
3859                            if (orderByComparator != null) {
3860                                    query = new StringBundler(2 +
3861                                                    (orderByComparator.getOrderByFields().length * 2));
3862    
3863                                    query.append(_SQL_SELECT_LAYOUTSETBRANCH);
3864    
3865                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3866                                            orderByComparator);
3867    
3868                                    sql = query.toString();
3869                            }
3870                            else {
3871                                    sql = _SQL_SELECT_LAYOUTSETBRANCH;
3872    
3873                                    if (pagination) {
3874                                            sql = sql.concat(LayoutSetBranchModelImpl.ORDER_BY_JPQL);
3875                                    }
3876                            }
3877    
3878                            Session session = null;
3879    
3880                            try {
3881                                    session = openSession();
3882    
3883                                    Query q = session.createQuery(sql);
3884    
3885                                    if (!pagination) {
3886                                            list = (List<LayoutSetBranch>)QueryUtil.list(q,
3887                                                            getDialect(), start, end, false);
3888    
3889                                            Collections.sort(list);
3890    
3891                                            list = Collections.unmodifiableList(list);
3892                                    }
3893                                    else {
3894                                            list = (List<LayoutSetBranch>)QueryUtil.list(q,
3895                                                            getDialect(), start, end);
3896                                    }
3897    
3898                                    cacheResult(list);
3899    
3900                                    finderCache.putResult(finderPath, finderArgs, list);
3901                            }
3902                            catch (Exception e) {
3903                                    finderCache.removeResult(finderPath, finderArgs);
3904    
3905                                    throw processException(e);
3906                            }
3907                            finally {
3908                                    closeSession(session);
3909                            }
3910                    }
3911    
3912                    return list;
3913            }
3914    
3915            /**
3916             * Removes all the layout set branchs from the database.
3917             *
3918             */
3919            @Override
3920            public void removeAll() {
3921                    for (LayoutSetBranch layoutSetBranch : findAll()) {
3922                            remove(layoutSetBranch);
3923                    }
3924            }
3925    
3926            /**
3927             * Returns the number of layout set branchs.
3928             *
3929             * @return the number of layout set branchs
3930             */
3931            @Override
3932            public int countAll() {
3933                    Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
3934                                    FINDER_ARGS_EMPTY, this);
3935    
3936                    if (count == null) {
3937                            Session session = null;
3938    
3939                            try {
3940                                    session = openSession();
3941    
3942                                    Query q = session.createQuery(_SQL_COUNT_LAYOUTSETBRANCH);
3943    
3944                                    count = (Long)q.uniqueResult();
3945    
3946                                    finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
3947                                            count);
3948                            }
3949                            catch (Exception e) {
3950                                    finderCache.removeResult(FINDER_PATH_COUNT_ALL,
3951                                            FINDER_ARGS_EMPTY);
3952    
3953                                    throw processException(e);
3954                            }
3955                            finally {
3956                                    closeSession(session);
3957                            }
3958                    }
3959    
3960                    return count.intValue();
3961            }
3962    
3963            @Override
3964            public Set<String> getBadColumnNames() {
3965                    return _badColumnNames;
3966            }
3967    
3968            @Override
3969            protected Map<String, Integer> getTableColumnsMap() {
3970                    return LayoutSetBranchModelImpl.TABLE_COLUMNS_MAP;
3971            }
3972    
3973            /**
3974             * Initializes the layout set branch persistence.
3975             */
3976            public void afterPropertiesSet() {
3977            }
3978    
3979            public void destroy() {
3980                    entityCache.removeCache(LayoutSetBranchImpl.class.getName());
3981                    finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
3982                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3983                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3984            }
3985    
3986            @BeanReference(type = CompanyProviderWrapper.class)
3987            protected CompanyProvider companyProvider;
3988            protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
3989            protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
3990            private static final String _SQL_SELECT_LAYOUTSETBRANCH = "SELECT layoutSetBranch FROM LayoutSetBranch layoutSetBranch";
3991            private static final String _SQL_SELECT_LAYOUTSETBRANCH_WHERE_PKS_IN = "SELECT layoutSetBranch FROM LayoutSetBranch layoutSetBranch WHERE layoutSetBranchId IN (";
3992            private static final String _SQL_SELECT_LAYOUTSETBRANCH_WHERE = "SELECT layoutSetBranch FROM LayoutSetBranch layoutSetBranch WHERE ";
3993            private static final String _SQL_COUNT_LAYOUTSETBRANCH = "SELECT COUNT(layoutSetBranch) FROM LayoutSetBranch layoutSetBranch";
3994            private static final String _SQL_COUNT_LAYOUTSETBRANCH_WHERE = "SELECT COUNT(layoutSetBranch) FROM LayoutSetBranch layoutSetBranch WHERE ";
3995            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "layoutSetBranch.layoutSetBranchId";
3996            private static final String _FILTER_SQL_SELECT_LAYOUTSETBRANCH_WHERE = "SELECT DISTINCT {layoutSetBranch.*} FROM LayoutSetBranch layoutSetBranch WHERE ";
3997            private static final String _FILTER_SQL_SELECT_LAYOUTSETBRANCH_NO_INLINE_DISTINCT_WHERE_1 =
3998                    "SELECT {LayoutSetBranch.*} FROM (SELECT DISTINCT layoutSetBranch.layoutSetBranchId FROM LayoutSetBranch layoutSetBranch WHERE ";
3999            private static final String _FILTER_SQL_SELECT_LAYOUTSETBRANCH_NO_INLINE_DISTINCT_WHERE_2 =
4000                    ") TEMP_TABLE INNER JOIN LayoutSetBranch ON TEMP_TABLE.layoutSetBranchId = LayoutSetBranch.layoutSetBranchId";
4001            private static final String _FILTER_SQL_COUNT_LAYOUTSETBRANCH_WHERE = "SELECT COUNT(DISTINCT layoutSetBranch.layoutSetBranchId) AS COUNT_VALUE FROM LayoutSetBranch layoutSetBranch WHERE ";
4002            private static final String _FILTER_ENTITY_ALIAS = "layoutSetBranch";
4003            private static final String _FILTER_ENTITY_TABLE = "LayoutSetBranch";
4004            private static final String _ORDER_BY_ENTITY_ALIAS = "layoutSetBranch.";
4005            private static final String _ORDER_BY_ENTITY_TABLE = "LayoutSetBranch.";
4006            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No LayoutSetBranch exists with the primary key ";
4007            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No LayoutSetBranch exists with the key {";
4008            private static final Log _log = LogFactoryUtil.getLog(LayoutSetBranchPersistenceImpl.class);
4009            private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
4010                                    "settings"
4011                            });
4012            private static final LayoutSetBranch _nullLayoutSetBranch = new LayoutSetBranchImpl() {
4013                            @Override
4014                            public Object clone() {
4015                                    return this;
4016                            }
4017    
4018                            @Override
4019                            public CacheModel<LayoutSetBranch> toCacheModel() {
4020                                    return _nullLayoutSetBranchCacheModel;
4021                            }
4022                    };
4023    
4024            private static final CacheModel<LayoutSetBranch> _nullLayoutSetBranchCacheModel =
4025                    new NullCacheModel();
4026    
4027            private static class NullCacheModel implements CacheModel<LayoutSetBranch>,
4028                    MVCCModel {
4029                    @Override
4030                    public long getMvccVersion() {
4031                            return -1;
4032                    }
4033    
4034                    @Override
4035                    public void setMvccVersion(long mvccVersion) {
4036                    }
4037    
4038                    @Override
4039                    public LayoutSetBranch toEntityModel() {
4040                            return _nullLayoutSetBranch;
4041                    }
4042            }
4043    }