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