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