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