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