001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.service.persistence.impl;
016    
017    import aQute.bnd.annotation.ProviderType;
018    
019    import com.liferay.portal.exception.NoSuchRecentLayoutSetBranchException;
020    import com.liferay.portal.kernel.bean.BeanReference;
021    import com.liferay.portal.kernel.dao.orm.EntityCache;
022    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
023    import com.liferay.portal.kernel.dao.orm.FinderCache;
024    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
025    import com.liferay.portal.kernel.dao.orm.FinderPath;
026    import com.liferay.portal.kernel.dao.orm.Query;
027    import com.liferay.portal.kernel.dao.orm.QueryPos;
028    import com.liferay.portal.kernel.dao.orm.QueryUtil;
029    import com.liferay.portal.kernel.dao.orm.Session;
030    import com.liferay.portal.kernel.log.Log;
031    import com.liferay.portal.kernel.log.LogFactoryUtil;
032    import com.liferay.portal.kernel.util.OrderByComparator;
033    import com.liferay.portal.kernel.util.StringBundler;
034    import com.liferay.portal.kernel.util.StringPool;
035    import com.liferay.portal.model.CacheModel;
036    import com.liferay.portal.model.MVCCModel;
037    import com.liferay.portal.model.RecentLayoutSetBranch;
038    import com.liferay.portal.model.impl.RecentLayoutSetBranchImpl;
039    import com.liferay.portal.model.impl.RecentLayoutSetBranchModelImpl;
040    import com.liferay.portal.service.persistence.CompanyProvider;
041    import com.liferay.portal.service.persistence.CompanyProviderWrapper;
042    import com.liferay.portal.service.persistence.RecentLayoutSetBranchPersistence;
043    
044    import java.io.Serializable;
045    
046    import java.util.Collections;
047    import java.util.HashMap;
048    import java.util.HashSet;
049    import java.util.Iterator;
050    import java.util.List;
051    import java.util.Map;
052    import java.util.Set;
053    
054    /**
055     * The persistence implementation for the recent layout set branch service.
056     *
057     * <p>
058     * Caching information and settings can be found in <code>portal.properties</code>
059     * </p>
060     *
061     * @author Brian Wing Shun Chan
062     * @see RecentLayoutSetBranchPersistence
063     * @see com.liferay.portal.service.persistence.RecentLayoutSetBranchUtil
064     * @generated
065     */
066    @ProviderType
067    public class RecentLayoutSetBranchPersistenceImpl extends BasePersistenceImpl<RecentLayoutSetBranch>
068            implements RecentLayoutSetBranchPersistence {
069            /*
070             * NOTE FOR DEVELOPERS:
071             *
072             * Never modify or reference this class directly. Always use {@link RecentLayoutSetBranchUtil} to access the recent layout set branch persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
073             */
074            public static final String FINDER_CLASS_NAME_ENTITY = RecentLayoutSetBranchImpl.class.getName();
075            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
076                    ".List1";
077            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
078                    ".List2";
079            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(RecentLayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
080                            RecentLayoutSetBranchModelImpl.FINDER_CACHE_ENABLED,
081                            RecentLayoutSetBranchImpl.class,
082                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
083            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(RecentLayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
084                            RecentLayoutSetBranchModelImpl.FINDER_CACHE_ENABLED,
085                            RecentLayoutSetBranchImpl.class,
086                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
087            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(RecentLayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
088                            RecentLayoutSetBranchModelImpl.FINDER_CACHE_ENABLED, Long.class,
089                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
090            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(RecentLayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
091                            RecentLayoutSetBranchModelImpl.FINDER_CACHE_ENABLED,
092                            RecentLayoutSetBranchImpl.class,
093                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
094                            new String[] {
095                                    Long.class.getName(),
096                                    
097                            Integer.class.getName(), Integer.class.getName(),
098                                    OrderByComparator.class.getName()
099                            });
100            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
101                    new FinderPath(RecentLayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
102                            RecentLayoutSetBranchModelImpl.FINDER_CACHE_ENABLED,
103                            RecentLayoutSetBranchImpl.class,
104                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
105                            new String[] { Long.class.getName() },
106                            RecentLayoutSetBranchModelImpl.GROUPID_COLUMN_BITMASK);
107            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(RecentLayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
108                            RecentLayoutSetBranchModelImpl.FINDER_CACHE_ENABLED, Long.class,
109                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
110                            new String[] { Long.class.getName() });
111    
112            /**
113             * Returns all the recent layout set branchs where groupId = &#63;.
114             *
115             * @param groupId the group ID
116             * @return the matching recent layout set branchs
117             */
118            @Override
119            public List<RecentLayoutSetBranch> findByGroupId(long groupId) {
120                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
121            }
122    
123            /**
124             * Returns a range of all the recent layout set branchs where groupId = &#63;.
125             *
126             * <p>
127             * 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 RecentLayoutSetBranchModelImpl}. 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.
128             * </p>
129             *
130             * @param groupId the group ID
131             * @param start the lower bound of the range of recent layout set branchs
132             * @param end the upper bound of the range of recent layout set branchs (not inclusive)
133             * @return the range of matching recent layout set branchs
134             */
135            @Override
136            public List<RecentLayoutSetBranch> findByGroupId(long groupId, int start,
137                    int end) {
138                    return findByGroupId(groupId, start, end, null);
139            }
140    
141            /**
142             * Returns an ordered range of all the recent layout set branchs where groupId = &#63;.
143             *
144             * <p>
145             * 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 RecentLayoutSetBranchModelImpl}. 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.
146             * </p>
147             *
148             * @param groupId the group ID
149             * @param start the lower bound of the range of recent layout set branchs
150             * @param end the upper bound of the range of recent layout set branchs (not inclusive)
151             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
152             * @return the ordered range of matching recent layout set branchs
153             */
154            @Override
155            public List<RecentLayoutSetBranch> findByGroupId(long groupId, int start,
156                    int end, OrderByComparator<RecentLayoutSetBranch> orderByComparator) {
157                    return findByGroupId(groupId, start, end, orderByComparator, true);
158            }
159    
160            /**
161             * Returns an ordered range of all the recent layout set branchs where groupId = &#63;.
162             *
163             * <p>
164             * 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 RecentLayoutSetBranchModelImpl}. 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.
165             * </p>
166             *
167             * @param groupId the group ID
168             * @param start the lower bound of the range of recent layout set branchs
169             * @param end the upper bound of the range of recent layout set branchs (not inclusive)
170             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
171             * @param retrieveFromCache whether to retrieve from the finder cache
172             * @return the ordered range of matching recent layout set branchs
173             */
174            @Override
175            public List<RecentLayoutSetBranch> findByGroupId(long groupId, int start,
176                    int end, OrderByComparator<RecentLayoutSetBranch> orderByComparator,
177                    boolean retrieveFromCache) {
178                    boolean pagination = true;
179                    FinderPath finderPath = null;
180                    Object[] finderArgs = null;
181    
182                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
183                                    (orderByComparator == null)) {
184                            pagination = false;
185                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
186                            finderArgs = new Object[] { groupId };
187                    }
188                    else {
189                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
190                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
191                    }
192    
193                    List<RecentLayoutSetBranch> list = null;
194    
195                    if (retrieveFromCache) {
196                            list = (List<RecentLayoutSetBranch>)finderCache.getResult(finderPath,
197                                            finderArgs, this);
198    
199                            if ((list != null) && !list.isEmpty()) {
200                                    for (RecentLayoutSetBranch recentLayoutSetBranch : list) {
201                                            if ((groupId != recentLayoutSetBranch.getGroupId())) {
202                                                    list = null;
203    
204                                                    break;
205                                            }
206                                    }
207                            }
208                    }
209    
210                    if (list == null) {
211                            StringBundler query = null;
212    
213                            if (orderByComparator != null) {
214                                    query = new StringBundler(3 +
215                                                    (orderByComparator.getOrderByFields().length * 3));
216                            }
217                            else {
218                                    query = new StringBundler(3);
219                            }
220    
221                            query.append(_SQL_SELECT_RECENTLAYOUTSETBRANCH_WHERE);
222    
223                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
224    
225                            if (orderByComparator != null) {
226                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
227                                            orderByComparator);
228                            }
229                            else
230                             if (pagination) {
231                                    query.append(RecentLayoutSetBranchModelImpl.ORDER_BY_JPQL);
232                            }
233    
234                            String sql = query.toString();
235    
236                            Session session = null;
237    
238                            try {
239                                    session = openSession();
240    
241                                    Query q = session.createQuery(sql);
242    
243                                    QueryPos qPos = QueryPos.getInstance(q);
244    
245                                    qPos.add(groupId);
246    
247                                    if (!pagination) {
248                                            list = (List<RecentLayoutSetBranch>)QueryUtil.list(q,
249                                                            getDialect(), start, end, false);
250    
251                                            Collections.sort(list);
252    
253                                            list = Collections.unmodifiableList(list);
254                                    }
255                                    else {
256                                            list = (List<RecentLayoutSetBranch>)QueryUtil.list(q,
257                                                            getDialect(), start, end);
258                                    }
259    
260                                    cacheResult(list);
261    
262                                    finderCache.putResult(finderPath, finderArgs, list);
263                            }
264                            catch (Exception e) {
265                                    finderCache.removeResult(finderPath, finderArgs);
266    
267                                    throw processException(e);
268                            }
269                            finally {
270                                    closeSession(session);
271                            }
272                    }
273    
274                    return list;
275            }
276    
277            /**
278             * Returns the first recent layout set branch in the ordered set where groupId = &#63;.
279             *
280             * @param groupId the group ID
281             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
282             * @return the first matching recent layout set branch
283             * @throws NoSuchRecentLayoutSetBranchException if a matching recent layout set branch could not be found
284             */
285            @Override
286            public RecentLayoutSetBranch findByGroupId_First(long groupId,
287                    OrderByComparator<RecentLayoutSetBranch> orderByComparator)
288                    throws NoSuchRecentLayoutSetBranchException {
289                    RecentLayoutSetBranch recentLayoutSetBranch = fetchByGroupId_First(groupId,
290                                    orderByComparator);
291    
292                    if (recentLayoutSetBranch != null) {
293                            return recentLayoutSetBranch;
294                    }
295    
296                    StringBundler msg = new StringBundler(4);
297    
298                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
299    
300                    msg.append("groupId=");
301                    msg.append(groupId);
302    
303                    msg.append(StringPool.CLOSE_CURLY_BRACE);
304    
305                    throw new NoSuchRecentLayoutSetBranchException(msg.toString());
306            }
307    
308            /**
309             * Returns the first recent layout set branch in the ordered set where groupId = &#63;.
310             *
311             * @param groupId the group ID
312             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
313             * @return the first matching recent layout set branch, or <code>null</code> if a matching recent layout set branch could not be found
314             */
315            @Override
316            public RecentLayoutSetBranch fetchByGroupId_First(long groupId,
317                    OrderByComparator<RecentLayoutSetBranch> orderByComparator) {
318                    List<RecentLayoutSetBranch> list = findByGroupId(groupId, 0, 1,
319                                    orderByComparator);
320    
321                    if (!list.isEmpty()) {
322                            return list.get(0);
323                    }
324    
325                    return null;
326            }
327    
328            /**
329             * Returns the last recent layout set branch in the ordered set where groupId = &#63;.
330             *
331             * @param groupId the group ID
332             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
333             * @return the last matching recent layout set branch
334             * @throws NoSuchRecentLayoutSetBranchException if a matching recent layout set branch could not be found
335             */
336            @Override
337            public RecentLayoutSetBranch findByGroupId_Last(long groupId,
338                    OrderByComparator<RecentLayoutSetBranch> orderByComparator)
339                    throws NoSuchRecentLayoutSetBranchException {
340                    RecentLayoutSetBranch recentLayoutSetBranch = fetchByGroupId_Last(groupId,
341                                    orderByComparator);
342    
343                    if (recentLayoutSetBranch != null) {
344                            return recentLayoutSetBranch;
345                    }
346    
347                    StringBundler msg = new StringBundler(4);
348    
349                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
350    
351                    msg.append("groupId=");
352                    msg.append(groupId);
353    
354                    msg.append(StringPool.CLOSE_CURLY_BRACE);
355    
356                    throw new NoSuchRecentLayoutSetBranchException(msg.toString());
357            }
358    
359            /**
360             * Returns the last recent layout set branch in the ordered set where groupId = &#63;.
361             *
362             * @param groupId the group ID
363             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
364             * @return the last matching recent layout set branch, or <code>null</code> if a matching recent layout set branch could not be found
365             */
366            @Override
367            public RecentLayoutSetBranch fetchByGroupId_Last(long groupId,
368                    OrderByComparator<RecentLayoutSetBranch> orderByComparator) {
369                    int count = countByGroupId(groupId);
370    
371                    if (count == 0) {
372                            return null;
373                    }
374    
375                    List<RecentLayoutSetBranch> list = findByGroupId(groupId, count - 1,
376                                    count, orderByComparator);
377    
378                    if (!list.isEmpty()) {
379                            return list.get(0);
380                    }
381    
382                    return null;
383            }
384    
385            /**
386             * Returns the recent layout set branchs before and after the current recent layout set branch in the ordered set where groupId = &#63;.
387             *
388             * @param recentLayoutSetBranchId the primary key of the current recent layout set branch
389             * @param groupId the group ID
390             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
391             * @return the previous, current, and next recent layout set branch
392             * @throws NoSuchRecentLayoutSetBranchException if a recent layout set branch with the primary key could not be found
393             */
394            @Override
395            public RecentLayoutSetBranch[] findByGroupId_PrevAndNext(
396                    long recentLayoutSetBranchId, long groupId,
397                    OrderByComparator<RecentLayoutSetBranch> orderByComparator)
398                    throws NoSuchRecentLayoutSetBranchException {
399                    RecentLayoutSetBranch recentLayoutSetBranch = findByPrimaryKey(recentLayoutSetBranchId);
400    
401                    Session session = null;
402    
403                    try {
404                            session = openSession();
405    
406                            RecentLayoutSetBranch[] array = new RecentLayoutSetBranchImpl[3];
407    
408                            array[0] = getByGroupId_PrevAndNext(session, recentLayoutSetBranch,
409                                            groupId, orderByComparator, true);
410    
411                            array[1] = recentLayoutSetBranch;
412    
413                            array[2] = getByGroupId_PrevAndNext(session, recentLayoutSetBranch,
414                                            groupId, orderByComparator, false);
415    
416                            return array;
417                    }
418                    catch (Exception e) {
419                            throw processException(e);
420                    }
421                    finally {
422                            closeSession(session);
423                    }
424            }
425    
426            protected RecentLayoutSetBranch getByGroupId_PrevAndNext(Session session,
427                    RecentLayoutSetBranch recentLayoutSetBranch, long groupId,
428                    OrderByComparator<RecentLayoutSetBranch> orderByComparator,
429                    boolean previous) {
430                    StringBundler query = null;
431    
432                    if (orderByComparator != null) {
433                            query = new StringBundler(6 +
434                                            (orderByComparator.getOrderByFields().length * 6));
435                    }
436                    else {
437                            query = new StringBundler(3);
438                    }
439    
440                    query.append(_SQL_SELECT_RECENTLAYOUTSETBRANCH_WHERE);
441    
442                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
443    
444                    if (orderByComparator != null) {
445                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
446    
447                            if (orderByConditionFields.length > 0) {
448                                    query.append(WHERE_AND);
449                            }
450    
451                            for (int i = 0; i < orderByConditionFields.length; i++) {
452                                    query.append(_ORDER_BY_ENTITY_ALIAS);
453                                    query.append(orderByConditionFields[i]);
454    
455                                    if ((i + 1) < orderByConditionFields.length) {
456                                            if (orderByComparator.isAscending() ^ previous) {
457                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
458                                            }
459                                            else {
460                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
461                                            }
462                                    }
463                                    else {
464                                            if (orderByComparator.isAscending() ^ previous) {
465                                                    query.append(WHERE_GREATER_THAN);
466                                            }
467                                            else {
468                                                    query.append(WHERE_LESSER_THAN);
469                                            }
470                                    }
471                            }
472    
473                            query.append(ORDER_BY_CLAUSE);
474    
475                            String[] orderByFields = orderByComparator.getOrderByFields();
476    
477                            for (int i = 0; i < orderByFields.length; i++) {
478                                    query.append(_ORDER_BY_ENTITY_ALIAS);
479                                    query.append(orderByFields[i]);
480    
481                                    if ((i + 1) < orderByFields.length) {
482                                            if (orderByComparator.isAscending() ^ previous) {
483                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
484                                            }
485                                            else {
486                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
487                                            }
488                                    }
489                                    else {
490                                            if (orderByComparator.isAscending() ^ previous) {
491                                                    query.append(ORDER_BY_ASC);
492                                            }
493                                            else {
494                                                    query.append(ORDER_BY_DESC);
495                                            }
496                                    }
497                            }
498                    }
499                    else {
500                            query.append(RecentLayoutSetBranchModelImpl.ORDER_BY_JPQL);
501                    }
502    
503                    String sql = query.toString();
504    
505                    Query q = session.createQuery(sql);
506    
507                    q.setFirstResult(0);
508                    q.setMaxResults(2);
509    
510                    QueryPos qPos = QueryPos.getInstance(q);
511    
512                    qPos.add(groupId);
513    
514                    if (orderByComparator != null) {
515                            Object[] values = orderByComparator.getOrderByConditionValues(recentLayoutSetBranch);
516    
517                            for (Object value : values) {
518                                    qPos.add(value);
519                            }
520                    }
521    
522                    List<RecentLayoutSetBranch> list = q.list();
523    
524                    if (list.size() == 2) {
525                            return list.get(1);
526                    }
527                    else {
528                            return null;
529                    }
530            }
531    
532            /**
533             * Removes all the recent layout set branchs where groupId = &#63; from the database.
534             *
535             * @param groupId the group ID
536             */
537            @Override
538            public void removeByGroupId(long groupId) {
539                    for (RecentLayoutSetBranch recentLayoutSetBranch : findByGroupId(
540                                    groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
541                            remove(recentLayoutSetBranch);
542                    }
543            }
544    
545            /**
546             * Returns the number of recent layout set branchs where groupId = &#63;.
547             *
548             * @param groupId the group ID
549             * @return the number of matching recent layout set branchs
550             */
551            @Override
552            public int countByGroupId(long groupId) {
553                    FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
554    
555                    Object[] finderArgs = new Object[] { groupId };
556    
557                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
558    
559                    if (count == null) {
560                            StringBundler query = new StringBundler(2);
561    
562                            query.append(_SQL_COUNT_RECENTLAYOUTSETBRANCH_WHERE);
563    
564                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
565    
566                            String sql = query.toString();
567    
568                            Session session = null;
569    
570                            try {
571                                    session = openSession();
572    
573                                    Query q = session.createQuery(sql);
574    
575                                    QueryPos qPos = QueryPos.getInstance(q);
576    
577                                    qPos.add(groupId);
578    
579                                    count = (Long)q.uniqueResult();
580    
581                                    finderCache.putResult(finderPath, finderArgs, count);
582                            }
583                            catch (Exception e) {
584                                    finderCache.removeResult(finderPath, finderArgs);
585    
586                                    throw processException(e);
587                            }
588                            finally {
589                                    closeSession(session);
590                            }
591                    }
592    
593                    return count.intValue();
594            }
595    
596            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "recentLayoutSetBranch.groupId = ?";
597            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(RecentLayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
598                            RecentLayoutSetBranchModelImpl.FINDER_CACHE_ENABLED,
599                            RecentLayoutSetBranchImpl.class,
600                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUserId",
601                            new String[] {
602                                    Long.class.getName(),
603                                    
604                            Integer.class.getName(), Integer.class.getName(),
605                                    OrderByComparator.class.getName()
606                            });
607            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID =
608                    new FinderPath(RecentLayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
609                            RecentLayoutSetBranchModelImpl.FINDER_CACHE_ENABLED,
610                            RecentLayoutSetBranchImpl.class,
611                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId",
612                            new String[] { Long.class.getName() },
613                            RecentLayoutSetBranchModelImpl.USERID_COLUMN_BITMASK);
614            public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(RecentLayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
615                            RecentLayoutSetBranchModelImpl.FINDER_CACHE_ENABLED, Long.class,
616                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
617                            new String[] { Long.class.getName() });
618    
619            /**
620             * Returns all the recent layout set branchs where userId = &#63;.
621             *
622             * @param userId the user ID
623             * @return the matching recent layout set branchs
624             */
625            @Override
626            public List<RecentLayoutSetBranch> findByUserId(long userId) {
627                    return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
628            }
629    
630            /**
631             * Returns a range of all the recent layout set branchs where userId = &#63;.
632             *
633             * <p>
634             * 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 RecentLayoutSetBranchModelImpl}. 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.
635             * </p>
636             *
637             * @param userId the user ID
638             * @param start the lower bound of the range of recent layout set branchs
639             * @param end the upper bound of the range of recent layout set branchs (not inclusive)
640             * @return the range of matching recent layout set branchs
641             */
642            @Override
643            public List<RecentLayoutSetBranch> findByUserId(long userId, int start,
644                    int end) {
645                    return findByUserId(userId, start, end, null);
646            }
647    
648            /**
649             * Returns an ordered range of all the recent layout set branchs where userId = &#63;.
650             *
651             * <p>
652             * 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 RecentLayoutSetBranchModelImpl}. 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.
653             * </p>
654             *
655             * @param userId the user ID
656             * @param start the lower bound of the range of recent layout set branchs
657             * @param end the upper bound of the range of recent layout set branchs (not inclusive)
658             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
659             * @return the ordered range of matching recent layout set branchs
660             */
661            @Override
662            public List<RecentLayoutSetBranch> findByUserId(long userId, int start,
663                    int end, OrderByComparator<RecentLayoutSetBranch> orderByComparator) {
664                    return findByUserId(userId, start, end, orderByComparator, true);
665            }
666    
667            /**
668             * Returns an ordered range of all the recent layout set branchs where userId = &#63;.
669             *
670             * <p>
671             * 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 RecentLayoutSetBranchModelImpl}. 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.
672             * </p>
673             *
674             * @param userId the user ID
675             * @param start the lower bound of the range of recent layout set branchs
676             * @param end the upper bound of the range of recent layout set branchs (not inclusive)
677             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
678             * @param retrieveFromCache whether to retrieve from the finder cache
679             * @return the ordered range of matching recent layout set branchs
680             */
681            @Override
682            public List<RecentLayoutSetBranch> findByUserId(long userId, int start,
683                    int end, OrderByComparator<RecentLayoutSetBranch> orderByComparator,
684                    boolean retrieveFromCache) {
685                    boolean pagination = true;
686                    FinderPath finderPath = null;
687                    Object[] finderArgs = null;
688    
689                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
690                                    (orderByComparator == null)) {
691                            pagination = false;
692                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
693                            finderArgs = new Object[] { userId };
694                    }
695                    else {
696                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
697                            finderArgs = new Object[] { userId, start, end, orderByComparator };
698                    }
699    
700                    List<RecentLayoutSetBranch> list = null;
701    
702                    if (retrieveFromCache) {
703                            list = (List<RecentLayoutSetBranch>)finderCache.getResult(finderPath,
704                                            finderArgs, this);
705    
706                            if ((list != null) && !list.isEmpty()) {
707                                    for (RecentLayoutSetBranch recentLayoutSetBranch : list) {
708                                            if ((userId != recentLayoutSetBranch.getUserId())) {
709                                                    list = null;
710    
711                                                    break;
712                                            }
713                                    }
714                            }
715                    }
716    
717                    if (list == null) {
718                            StringBundler query = null;
719    
720                            if (orderByComparator != null) {
721                                    query = new StringBundler(3 +
722                                                    (orderByComparator.getOrderByFields().length * 3));
723                            }
724                            else {
725                                    query = new StringBundler(3);
726                            }
727    
728                            query.append(_SQL_SELECT_RECENTLAYOUTSETBRANCH_WHERE);
729    
730                            query.append(_FINDER_COLUMN_USERID_USERID_2);
731    
732                            if (orderByComparator != null) {
733                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
734                                            orderByComparator);
735                            }
736                            else
737                             if (pagination) {
738                                    query.append(RecentLayoutSetBranchModelImpl.ORDER_BY_JPQL);
739                            }
740    
741                            String sql = query.toString();
742    
743                            Session session = null;
744    
745                            try {
746                                    session = openSession();
747    
748                                    Query q = session.createQuery(sql);
749    
750                                    QueryPos qPos = QueryPos.getInstance(q);
751    
752                                    qPos.add(userId);
753    
754                                    if (!pagination) {
755                                            list = (List<RecentLayoutSetBranch>)QueryUtil.list(q,
756                                                            getDialect(), start, end, false);
757    
758                                            Collections.sort(list);
759    
760                                            list = Collections.unmodifiableList(list);
761                                    }
762                                    else {
763                                            list = (List<RecentLayoutSetBranch>)QueryUtil.list(q,
764                                                            getDialect(), start, end);
765                                    }
766    
767                                    cacheResult(list);
768    
769                                    finderCache.putResult(finderPath, finderArgs, list);
770                            }
771                            catch (Exception e) {
772                                    finderCache.removeResult(finderPath, finderArgs);
773    
774                                    throw processException(e);
775                            }
776                            finally {
777                                    closeSession(session);
778                            }
779                    }
780    
781                    return list;
782            }
783    
784            /**
785             * Returns the first recent layout set branch in the ordered set where userId = &#63;.
786             *
787             * @param userId the user ID
788             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
789             * @return the first matching recent layout set branch
790             * @throws NoSuchRecentLayoutSetBranchException if a matching recent layout set branch could not be found
791             */
792            @Override
793            public RecentLayoutSetBranch findByUserId_First(long userId,
794                    OrderByComparator<RecentLayoutSetBranch> orderByComparator)
795                    throws NoSuchRecentLayoutSetBranchException {
796                    RecentLayoutSetBranch recentLayoutSetBranch = fetchByUserId_First(userId,
797                                    orderByComparator);
798    
799                    if (recentLayoutSetBranch != null) {
800                            return recentLayoutSetBranch;
801                    }
802    
803                    StringBundler msg = new StringBundler(4);
804    
805                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
806    
807                    msg.append("userId=");
808                    msg.append(userId);
809    
810                    msg.append(StringPool.CLOSE_CURLY_BRACE);
811    
812                    throw new NoSuchRecentLayoutSetBranchException(msg.toString());
813            }
814    
815            /**
816             * Returns the first recent layout set branch in the ordered set where userId = &#63;.
817             *
818             * @param userId the user ID
819             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
820             * @return the first matching recent layout set branch, or <code>null</code> if a matching recent layout set branch could not be found
821             */
822            @Override
823            public RecentLayoutSetBranch fetchByUserId_First(long userId,
824                    OrderByComparator<RecentLayoutSetBranch> orderByComparator) {
825                    List<RecentLayoutSetBranch> list = findByUserId(userId, 0, 1,
826                                    orderByComparator);
827    
828                    if (!list.isEmpty()) {
829                            return list.get(0);
830                    }
831    
832                    return null;
833            }
834    
835            /**
836             * Returns the last recent layout set branch in the ordered set where userId = &#63;.
837             *
838             * @param userId the user ID
839             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
840             * @return the last matching recent layout set branch
841             * @throws NoSuchRecentLayoutSetBranchException if a matching recent layout set branch could not be found
842             */
843            @Override
844            public RecentLayoutSetBranch findByUserId_Last(long userId,
845                    OrderByComparator<RecentLayoutSetBranch> orderByComparator)
846                    throws NoSuchRecentLayoutSetBranchException {
847                    RecentLayoutSetBranch recentLayoutSetBranch = fetchByUserId_Last(userId,
848                                    orderByComparator);
849    
850                    if (recentLayoutSetBranch != null) {
851                            return recentLayoutSetBranch;
852                    }
853    
854                    StringBundler msg = new StringBundler(4);
855    
856                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
857    
858                    msg.append("userId=");
859                    msg.append(userId);
860    
861                    msg.append(StringPool.CLOSE_CURLY_BRACE);
862    
863                    throw new NoSuchRecentLayoutSetBranchException(msg.toString());
864            }
865    
866            /**
867             * Returns the last recent layout set branch in the ordered set where userId = &#63;.
868             *
869             * @param userId the user ID
870             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
871             * @return the last matching recent layout set branch, or <code>null</code> if a matching recent layout set branch could not be found
872             */
873            @Override
874            public RecentLayoutSetBranch fetchByUserId_Last(long userId,
875                    OrderByComparator<RecentLayoutSetBranch> orderByComparator) {
876                    int count = countByUserId(userId);
877    
878                    if (count == 0) {
879                            return null;
880                    }
881    
882                    List<RecentLayoutSetBranch> list = findByUserId(userId, count - 1,
883                                    count, orderByComparator);
884    
885                    if (!list.isEmpty()) {
886                            return list.get(0);
887                    }
888    
889                    return null;
890            }
891    
892            /**
893             * Returns the recent layout set branchs before and after the current recent layout set branch in the ordered set where userId = &#63;.
894             *
895             * @param recentLayoutSetBranchId the primary key of the current recent layout set branch
896             * @param userId the user ID
897             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
898             * @return the previous, current, and next recent layout set branch
899             * @throws NoSuchRecentLayoutSetBranchException if a recent layout set branch with the primary key could not be found
900             */
901            @Override
902            public RecentLayoutSetBranch[] findByUserId_PrevAndNext(
903                    long recentLayoutSetBranchId, long userId,
904                    OrderByComparator<RecentLayoutSetBranch> orderByComparator)
905                    throws NoSuchRecentLayoutSetBranchException {
906                    RecentLayoutSetBranch recentLayoutSetBranch = findByPrimaryKey(recentLayoutSetBranchId);
907    
908                    Session session = null;
909    
910                    try {
911                            session = openSession();
912    
913                            RecentLayoutSetBranch[] array = new RecentLayoutSetBranchImpl[3];
914    
915                            array[0] = getByUserId_PrevAndNext(session, recentLayoutSetBranch,
916                                            userId, orderByComparator, true);
917    
918                            array[1] = recentLayoutSetBranch;
919    
920                            array[2] = getByUserId_PrevAndNext(session, recentLayoutSetBranch,
921                                            userId, orderByComparator, false);
922    
923                            return array;
924                    }
925                    catch (Exception e) {
926                            throw processException(e);
927                    }
928                    finally {
929                            closeSession(session);
930                    }
931            }
932    
933            protected RecentLayoutSetBranch getByUserId_PrevAndNext(Session session,
934                    RecentLayoutSetBranch recentLayoutSetBranch, long userId,
935                    OrderByComparator<RecentLayoutSetBranch> orderByComparator,
936                    boolean previous) {
937                    StringBundler query = null;
938    
939                    if (orderByComparator != null) {
940                            query = new StringBundler(6 +
941                                            (orderByComparator.getOrderByFields().length * 6));
942                    }
943                    else {
944                            query = new StringBundler(3);
945                    }
946    
947                    query.append(_SQL_SELECT_RECENTLAYOUTSETBRANCH_WHERE);
948    
949                    query.append(_FINDER_COLUMN_USERID_USERID_2);
950    
951                    if (orderByComparator != null) {
952                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
953    
954                            if (orderByConditionFields.length > 0) {
955                                    query.append(WHERE_AND);
956                            }
957    
958                            for (int i = 0; i < orderByConditionFields.length; i++) {
959                                    query.append(_ORDER_BY_ENTITY_ALIAS);
960                                    query.append(orderByConditionFields[i]);
961    
962                                    if ((i + 1) < orderByConditionFields.length) {
963                                            if (orderByComparator.isAscending() ^ previous) {
964                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
965                                            }
966                                            else {
967                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
968                                            }
969                                    }
970                                    else {
971                                            if (orderByComparator.isAscending() ^ previous) {
972                                                    query.append(WHERE_GREATER_THAN);
973                                            }
974                                            else {
975                                                    query.append(WHERE_LESSER_THAN);
976                                            }
977                                    }
978                            }
979    
980                            query.append(ORDER_BY_CLAUSE);
981    
982                            String[] orderByFields = orderByComparator.getOrderByFields();
983    
984                            for (int i = 0; i < orderByFields.length; i++) {
985                                    query.append(_ORDER_BY_ENTITY_ALIAS);
986                                    query.append(orderByFields[i]);
987    
988                                    if ((i + 1) < orderByFields.length) {
989                                            if (orderByComparator.isAscending() ^ previous) {
990                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
991                                            }
992                                            else {
993                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
994                                            }
995                                    }
996                                    else {
997                                            if (orderByComparator.isAscending() ^ previous) {
998                                                    query.append(ORDER_BY_ASC);
999                                            }
1000                                            else {
1001                                                    query.append(ORDER_BY_DESC);
1002                                            }
1003                                    }
1004                            }
1005                    }
1006                    else {
1007                            query.append(RecentLayoutSetBranchModelImpl.ORDER_BY_JPQL);
1008                    }
1009    
1010                    String sql = query.toString();
1011    
1012                    Query q = session.createQuery(sql);
1013    
1014                    q.setFirstResult(0);
1015                    q.setMaxResults(2);
1016    
1017                    QueryPos qPos = QueryPos.getInstance(q);
1018    
1019                    qPos.add(userId);
1020    
1021                    if (orderByComparator != null) {
1022                            Object[] values = orderByComparator.getOrderByConditionValues(recentLayoutSetBranch);
1023    
1024                            for (Object value : values) {
1025                                    qPos.add(value);
1026                            }
1027                    }
1028    
1029                    List<RecentLayoutSetBranch> list = q.list();
1030    
1031                    if (list.size() == 2) {
1032                            return list.get(1);
1033                    }
1034                    else {
1035                            return null;
1036                    }
1037            }
1038    
1039            /**
1040             * Removes all the recent layout set branchs where userId = &#63; from the database.
1041             *
1042             * @param userId the user ID
1043             */
1044            @Override
1045            public void removeByUserId(long userId) {
1046                    for (RecentLayoutSetBranch recentLayoutSetBranch : findByUserId(
1047                                    userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1048                            remove(recentLayoutSetBranch);
1049                    }
1050            }
1051    
1052            /**
1053             * Returns the number of recent layout set branchs where userId = &#63;.
1054             *
1055             * @param userId the user ID
1056             * @return the number of matching recent layout set branchs
1057             */
1058            @Override
1059            public int countByUserId(long userId) {
1060                    FinderPath finderPath = FINDER_PATH_COUNT_BY_USERID;
1061    
1062                    Object[] finderArgs = new Object[] { userId };
1063    
1064                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1065    
1066                    if (count == null) {
1067                            StringBundler query = new StringBundler(2);
1068    
1069                            query.append(_SQL_COUNT_RECENTLAYOUTSETBRANCH_WHERE);
1070    
1071                            query.append(_FINDER_COLUMN_USERID_USERID_2);
1072    
1073                            String sql = query.toString();
1074    
1075                            Session session = null;
1076    
1077                            try {
1078                                    session = openSession();
1079    
1080                                    Query q = session.createQuery(sql);
1081    
1082                                    QueryPos qPos = QueryPos.getInstance(q);
1083    
1084                                    qPos.add(userId);
1085    
1086                                    count = (Long)q.uniqueResult();
1087    
1088                                    finderCache.putResult(finderPath, finderArgs, count);
1089                            }
1090                            catch (Exception e) {
1091                                    finderCache.removeResult(finderPath, finderArgs);
1092    
1093                                    throw processException(e);
1094                            }
1095                            finally {
1096                                    closeSession(session);
1097                            }
1098                    }
1099    
1100                    return count.intValue();
1101            }
1102    
1103            private static final String _FINDER_COLUMN_USERID_USERID_2 = "recentLayoutSetBranch.userId = ?";
1104            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_LAYOUTSETBRANCHID =
1105                    new FinderPath(RecentLayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
1106                            RecentLayoutSetBranchModelImpl.FINDER_CACHE_ENABLED,
1107                            RecentLayoutSetBranchImpl.class,
1108                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByLayoutSetBranchId",
1109                            new String[] {
1110                                    Long.class.getName(),
1111                                    
1112                            Integer.class.getName(), Integer.class.getName(),
1113                                    OrderByComparator.class.getName()
1114                            });
1115            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LAYOUTSETBRANCHID =
1116                    new FinderPath(RecentLayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
1117                            RecentLayoutSetBranchModelImpl.FINDER_CACHE_ENABLED,
1118                            RecentLayoutSetBranchImpl.class,
1119                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
1120                            "findByLayoutSetBranchId", new String[] { Long.class.getName() },
1121                            RecentLayoutSetBranchModelImpl.LAYOUTSETBRANCHID_COLUMN_BITMASK);
1122            public static final FinderPath FINDER_PATH_COUNT_BY_LAYOUTSETBRANCHID = new FinderPath(RecentLayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
1123                            RecentLayoutSetBranchModelImpl.FINDER_CACHE_ENABLED, Long.class,
1124                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
1125                            "countByLayoutSetBranchId", new String[] { Long.class.getName() });
1126    
1127            /**
1128             * Returns all the recent layout set branchs where layoutSetBranchId = &#63;.
1129             *
1130             * @param layoutSetBranchId the layout set branch ID
1131             * @return the matching recent layout set branchs
1132             */
1133            @Override
1134            public List<RecentLayoutSetBranch> findByLayoutSetBranchId(
1135                    long layoutSetBranchId) {
1136                    return findByLayoutSetBranchId(layoutSetBranchId, QueryUtil.ALL_POS,
1137                            QueryUtil.ALL_POS, null);
1138            }
1139    
1140            /**
1141             * Returns a range of all the recent layout set branchs where layoutSetBranchId = &#63;.
1142             *
1143             * <p>
1144             * 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 RecentLayoutSetBranchModelImpl}. 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.
1145             * </p>
1146             *
1147             * @param layoutSetBranchId the layout set branch ID
1148             * @param start the lower bound of the range of recent layout set branchs
1149             * @param end the upper bound of the range of recent layout set branchs (not inclusive)
1150             * @return the range of matching recent layout set branchs
1151             */
1152            @Override
1153            public List<RecentLayoutSetBranch> findByLayoutSetBranchId(
1154                    long layoutSetBranchId, int start, int end) {
1155                    return findByLayoutSetBranchId(layoutSetBranchId, start, end, null);
1156            }
1157    
1158            /**
1159             * Returns an ordered range of all the recent layout set branchs where layoutSetBranchId = &#63;.
1160             *
1161             * <p>
1162             * 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 RecentLayoutSetBranchModelImpl}. 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.
1163             * </p>
1164             *
1165             * @param layoutSetBranchId the layout set branch ID
1166             * @param start the lower bound of the range of recent layout set branchs
1167             * @param end the upper bound of the range of recent layout set branchs (not inclusive)
1168             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1169             * @return the ordered range of matching recent layout set branchs
1170             */
1171            @Override
1172            public List<RecentLayoutSetBranch> findByLayoutSetBranchId(
1173                    long layoutSetBranchId, int start, int end,
1174                    OrderByComparator<RecentLayoutSetBranch> orderByComparator) {
1175                    return findByLayoutSetBranchId(layoutSetBranchId, start, end,
1176                            orderByComparator, true);
1177            }
1178    
1179            /**
1180             * Returns an ordered range of all the recent layout set branchs where layoutSetBranchId = &#63;.
1181             *
1182             * <p>
1183             * 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 RecentLayoutSetBranchModelImpl}. 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.
1184             * </p>
1185             *
1186             * @param layoutSetBranchId the layout set branch ID
1187             * @param start the lower bound of the range of recent layout set branchs
1188             * @param end the upper bound of the range of recent layout set branchs (not inclusive)
1189             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1190             * @param retrieveFromCache whether to retrieve from the finder cache
1191             * @return the ordered range of matching recent layout set branchs
1192             */
1193            @Override
1194            public List<RecentLayoutSetBranch> findByLayoutSetBranchId(
1195                    long layoutSetBranchId, int start, int end,
1196                    OrderByComparator<RecentLayoutSetBranch> orderByComparator,
1197                    boolean retrieveFromCache) {
1198                    boolean pagination = true;
1199                    FinderPath finderPath = null;
1200                    Object[] finderArgs = null;
1201    
1202                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1203                                    (orderByComparator == null)) {
1204                            pagination = false;
1205                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LAYOUTSETBRANCHID;
1206                            finderArgs = new Object[] { layoutSetBranchId };
1207                    }
1208                    else {
1209                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_LAYOUTSETBRANCHID;
1210                            finderArgs = new Object[] {
1211                                            layoutSetBranchId,
1212                                            
1213                                            start, end, orderByComparator
1214                                    };
1215                    }
1216    
1217                    List<RecentLayoutSetBranch> list = null;
1218    
1219                    if (retrieveFromCache) {
1220                            list = (List<RecentLayoutSetBranch>)finderCache.getResult(finderPath,
1221                                            finderArgs, this);
1222    
1223                            if ((list != null) && !list.isEmpty()) {
1224                                    for (RecentLayoutSetBranch recentLayoutSetBranch : list) {
1225                                            if ((layoutSetBranchId != recentLayoutSetBranch.getLayoutSetBranchId())) {
1226                                                    list = null;
1227    
1228                                                    break;
1229                                            }
1230                                    }
1231                            }
1232                    }
1233    
1234                    if (list == null) {
1235                            StringBundler query = null;
1236    
1237                            if (orderByComparator != null) {
1238                                    query = new StringBundler(3 +
1239                                                    (orderByComparator.getOrderByFields().length * 3));
1240                            }
1241                            else {
1242                                    query = new StringBundler(3);
1243                            }
1244    
1245                            query.append(_SQL_SELECT_RECENTLAYOUTSETBRANCH_WHERE);
1246    
1247                            query.append(_FINDER_COLUMN_LAYOUTSETBRANCHID_LAYOUTSETBRANCHID_2);
1248    
1249                            if (orderByComparator != null) {
1250                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1251                                            orderByComparator);
1252                            }
1253                            else
1254                             if (pagination) {
1255                                    query.append(RecentLayoutSetBranchModelImpl.ORDER_BY_JPQL);
1256                            }
1257    
1258                            String sql = query.toString();
1259    
1260                            Session session = null;
1261    
1262                            try {
1263                                    session = openSession();
1264    
1265                                    Query q = session.createQuery(sql);
1266    
1267                                    QueryPos qPos = QueryPos.getInstance(q);
1268    
1269                                    qPos.add(layoutSetBranchId);
1270    
1271                                    if (!pagination) {
1272                                            list = (List<RecentLayoutSetBranch>)QueryUtil.list(q,
1273                                                            getDialect(), start, end, false);
1274    
1275                                            Collections.sort(list);
1276    
1277                                            list = Collections.unmodifiableList(list);
1278                                    }
1279                                    else {
1280                                            list = (List<RecentLayoutSetBranch>)QueryUtil.list(q,
1281                                                            getDialect(), start, end);
1282                                    }
1283    
1284                                    cacheResult(list);
1285    
1286                                    finderCache.putResult(finderPath, finderArgs, list);
1287                            }
1288                            catch (Exception e) {
1289                                    finderCache.removeResult(finderPath, finderArgs);
1290    
1291                                    throw processException(e);
1292                            }
1293                            finally {
1294                                    closeSession(session);
1295                            }
1296                    }
1297    
1298                    return list;
1299            }
1300    
1301            /**
1302             * Returns the first recent layout set branch in the ordered set where layoutSetBranchId = &#63;.
1303             *
1304             * @param layoutSetBranchId the layout set branch ID
1305             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1306             * @return the first matching recent layout set branch
1307             * @throws NoSuchRecentLayoutSetBranchException if a matching recent layout set branch could not be found
1308             */
1309            @Override
1310            public RecentLayoutSetBranch findByLayoutSetBranchId_First(
1311                    long layoutSetBranchId,
1312                    OrderByComparator<RecentLayoutSetBranch> orderByComparator)
1313                    throws NoSuchRecentLayoutSetBranchException {
1314                    RecentLayoutSetBranch recentLayoutSetBranch = fetchByLayoutSetBranchId_First(layoutSetBranchId,
1315                                    orderByComparator);
1316    
1317                    if (recentLayoutSetBranch != null) {
1318                            return recentLayoutSetBranch;
1319                    }
1320    
1321                    StringBundler msg = new StringBundler(4);
1322    
1323                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1324    
1325                    msg.append("layoutSetBranchId=");
1326                    msg.append(layoutSetBranchId);
1327    
1328                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1329    
1330                    throw new NoSuchRecentLayoutSetBranchException(msg.toString());
1331            }
1332    
1333            /**
1334             * Returns the first recent layout set branch in the ordered set where layoutSetBranchId = &#63;.
1335             *
1336             * @param layoutSetBranchId the layout set branch ID
1337             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1338             * @return the first matching recent layout set branch, or <code>null</code> if a matching recent layout set branch could not be found
1339             */
1340            @Override
1341            public RecentLayoutSetBranch fetchByLayoutSetBranchId_First(
1342                    long layoutSetBranchId,
1343                    OrderByComparator<RecentLayoutSetBranch> orderByComparator) {
1344                    List<RecentLayoutSetBranch> list = findByLayoutSetBranchId(layoutSetBranchId,
1345                                    0, 1, orderByComparator);
1346    
1347                    if (!list.isEmpty()) {
1348                            return list.get(0);
1349                    }
1350    
1351                    return null;
1352            }
1353    
1354            /**
1355             * Returns the last recent layout set branch in the ordered set where layoutSetBranchId = &#63;.
1356             *
1357             * @param layoutSetBranchId the layout set branch ID
1358             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1359             * @return the last matching recent layout set branch
1360             * @throws NoSuchRecentLayoutSetBranchException if a matching recent layout set branch could not be found
1361             */
1362            @Override
1363            public RecentLayoutSetBranch findByLayoutSetBranchId_Last(
1364                    long layoutSetBranchId,
1365                    OrderByComparator<RecentLayoutSetBranch> orderByComparator)
1366                    throws NoSuchRecentLayoutSetBranchException {
1367                    RecentLayoutSetBranch recentLayoutSetBranch = fetchByLayoutSetBranchId_Last(layoutSetBranchId,
1368                                    orderByComparator);
1369    
1370                    if (recentLayoutSetBranch != null) {
1371                            return recentLayoutSetBranch;
1372                    }
1373    
1374                    StringBundler msg = new StringBundler(4);
1375    
1376                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1377    
1378                    msg.append("layoutSetBranchId=");
1379                    msg.append(layoutSetBranchId);
1380    
1381                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1382    
1383                    throw new NoSuchRecentLayoutSetBranchException(msg.toString());
1384            }
1385    
1386            /**
1387             * Returns the last recent layout set branch in the ordered set where layoutSetBranchId = &#63;.
1388             *
1389             * @param layoutSetBranchId the layout set branch ID
1390             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1391             * @return the last matching recent layout set branch, or <code>null</code> if a matching recent layout set branch could not be found
1392             */
1393            @Override
1394            public RecentLayoutSetBranch fetchByLayoutSetBranchId_Last(
1395                    long layoutSetBranchId,
1396                    OrderByComparator<RecentLayoutSetBranch> orderByComparator) {
1397                    int count = countByLayoutSetBranchId(layoutSetBranchId);
1398    
1399                    if (count == 0) {
1400                            return null;
1401                    }
1402    
1403                    List<RecentLayoutSetBranch> list = findByLayoutSetBranchId(layoutSetBranchId,
1404                                    count - 1, count, orderByComparator);
1405    
1406                    if (!list.isEmpty()) {
1407                            return list.get(0);
1408                    }
1409    
1410                    return null;
1411            }
1412    
1413            /**
1414             * Returns the recent layout set branchs before and after the current recent layout set branch in the ordered set where layoutSetBranchId = &#63;.
1415             *
1416             * @param recentLayoutSetBranchId the primary key of the current recent layout set branch
1417             * @param layoutSetBranchId the layout set branch ID
1418             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1419             * @return the previous, current, and next recent layout set branch
1420             * @throws NoSuchRecentLayoutSetBranchException if a recent layout set branch with the primary key could not be found
1421             */
1422            @Override
1423            public RecentLayoutSetBranch[] findByLayoutSetBranchId_PrevAndNext(
1424                    long recentLayoutSetBranchId, long layoutSetBranchId,
1425                    OrderByComparator<RecentLayoutSetBranch> orderByComparator)
1426                    throws NoSuchRecentLayoutSetBranchException {
1427                    RecentLayoutSetBranch recentLayoutSetBranch = findByPrimaryKey(recentLayoutSetBranchId);
1428    
1429                    Session session = null;
1430    
1431                    try {
1432                            session = openSession();
1433    
1434                            RecentLayoutSetBranch[] array = new RecentLayoutSetBranchImpl[3];
1435    
1436                            array[0] = getByLayoutSetBranchId_PrevAndNext(session,
1437                                            recentLayoutSetBranch, layoutSetBranchId,
1438                                            orderByComparator, true);
1439    
1440                            array[1] = recentLayoutSetBranch;
1441    
1442                            array[2] = getByLayoutSetBranchId_PrevAndNext(session,
1443                                            recentLayoutSetBranch, layoutSetBranchId,
1444                                            orderByComparator, false);
1445    
1446                            return array;
1447                    }
1448                    catch (Exception e) {
1449                            throw processException(e);
1450                    }
1451                    finally {
1452                            closeSession(session);
1453                    }
1454            }
1455    
1456            protected RecentLayoutSetBranch getByLayoutSetBranchId_PrevAndNext(
1457                    Session session, RecentLayoutSetBranch recentLayoutSetBranch,
1458                    long layoutSetBranchId,
1459                    OrderByComparator<RecentLayoutSetBranch> orderByComparator,
1460                    boolean previous) {
1461                    StringBundler query = null;
1462    
1463                    if (orderByComparator != null) {
1464                            query = new StringBundler(6 +
1465                                            (orderByComparator.getOrderByFields().length * 6));
1466                    }
1467                    else {
1468                            query = new StringBundler(3);
1469                    }
1470    
1471                    query.append(_SQL_SELECT_RECENTLAYOUTSETBRANCH_WHERE);
1472    
1473                    query.append(_FINDER_COLUMN_LAYOUTSETBRANCHID_LAYOUTSETBRANCHID_2);
1474    
1475                    if (orderByComparator != null) {
1476                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1477    
1478                            if (orderByConditionFields.length > 0) {
1479                                    query.append(WHERE_AND);
1480                            }
1481    
1482                            for (int i = 0; i < orderByConditionFields.length; i++) {
1483                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1484                                    query.append(orderByConditionFields[i]);
1485    
1486                                    if ((i + 1) < orderByConditionFields.length) {
1487                                            if (orderByComparator.isAscending() ^ previous) {
1488                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1489                                            }
1490                                            else {
1491                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1492                                            }
1493                                    }
1494                                    else {
1495                                            if (orderByComparator.isAscending() ^ previous) {
1496                                                    query.append(WHERE_GREATER_THAN);
1497                                            }
1498                                            else {
1499                                                    query.append(WHERE_LESSER_THAN);
1500                                            }
1501                                    }
1502                            }
1503    
1504                            query.append(ORDER_BY_CLAUSE);
1505    
1506                            String[] orderByFields = orderByComparator.getOrderByFields();
1507    
1508                            for (int i = 0; i < orderByFields.length; i++) {
1509                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1510                                    query.append(orderByFields[i]);
1511    
1512                                    if ((i + 1) < orderByFields.length) {
1513                                            if (orderByComparator.isAscending() ^ previous) {
1514                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1515                                            }
1516                                            else {
1517                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1518                                            }
1519                                    }
1520                                    else {
1521                                            if (orderByComparator.isAscending() ^ previous) {
1522                                                    query.append(ORDER_BY_ASC);
1523                                            }
1524                                            else {
1525                                                    query.append(ORDER_BY_DESC);
1526                                            }
1527                                    }
1528                            }
1529                    }
1530                    else {
1531                            query.append(RecentLayoutSetBranchModelImpl.ORDER_BY_JPQL);
1532                    }
1533    
1534                    String sql = query.toString();
1535    
1536                    Query q = session.createQuery(sql);
1537    
1538                    q.setFirstResult(0);
1539                    q.setMaxResults(2);
1540    
1541                    QueryPos qPos = QueryPos.getInstance(q);
1542    
1543                    qPos.add(layoutSetBranchId);
1544    
1545                    if (orderByComparator != null) {
1546                            Object[] values = orderByComparator.getOrderByConditionValues(recentLayoutSetBranch);
1547    
1548                            for (Object value : values) {
1549                                    qPos.add(value);
1550                            }
1551                    }
1552    
1553                    List<RecentLayoutSetBranch> list = q.list();
1554    
1555                    if (list.size() == 2) {
1556                            return list.get(1);
1557                    }
1558                    else {
1559                            return null;
1560                    }
1561            }
1562    
1563            /**
1564             * Removes all the recent layout set branchs where layoutSetBranchId = &#63; from the database.
1565             *
1566             * @param layoutSetBranchId the layout set branch ID
1567             */
1568            @Override
1569            public void removeByLayoutSetBranchId(long layoutSetBranchId) {
1570                    for (RecentLayoutSetBranch recentLayoutSetBranch : findByLayoutSetBranchId(
1571                                    layoutSetBranchId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1572                            remove(recentLayoutSetBranch);
1573                    }
1574            }
1575    
1576            /**
1577             * Returns the number of recent layout set branchs where layoutSetBranchId = &#63;.
1578             *
1579             * @param layoutSetBranchId the layout set branch ID
1580             * @return the number of matching recent layout set branchs
1581             */
1582            @Override
1583            public int countByLayoutSetBranchId(long layoutSetBranchId) {
1584                    FinderPath finderPath = FINDER_PATH_COUNT_BY_LAYOUTSETBRANCHID;
1585    
1586                    Object[] finderArgs = new Object[] { layoutSetBranchId };
1587    
1588                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1589    
1590                    if (count == null) {
1591                            StringBundler query = new StringBundler(2);
1592    
1593                            query.append(_SQL_COUNT_RECENTLAYOUTSETBRANCH_WHERE);
1594    
1595                            query.append(_FINDER_COLUMN_LAYOUTSETBRANCHID_LAYOUTSETBRANCHID_2);
1596    
1597                            String sql = query.toString();
1598    
1599                            Session session = null;
1600    
1601                            try {
1602                                    session = openSession();
1603    
1604                                    Query q = session.createQuery(sql);
1605    
1606                                    QueryPos qPos = QueryPos.getInstance(q);
1607    
1608                                    qPos.add(layoutSetBranchId);
1609    
1610                                    count = (Long)q.uniqueResult();
1611    
1612                                    finderCache.putResult(finderPath, finderArgs, count);
1613                            }
1614                            catch (Exception e) {
1615                                    finderCache.removeResult(finderPath, finderArgs);
1616    
1617                                    throw processException(e);
1618                            }
1619                            finally {
1620                                    closeSession(session);
1621                            }
1622                    }
1623    
1624                    return count.intValue();
1625            }
1626    
1627            private static final String _FINDER_COLUMN_LAYOUTSETBRANCHID_LAYOUTSETBRANCHID_2 =
1628                    "recentLayoutSetBranch.layoutSetBranchId = ?";
1629            public static final FinderPath FINDER_PATH_FETCH_BY_U_L = new FinderPath(RecentLayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
1630                            RecentLayoutSetBranchModelImpl.FINDER_CACHE_ENABLED,
1631                            RecentLayoutSetBranchImpl.class, FINDER_CLASS_NAME_ENTITY,
1632                            "fetchByU_L",
1633                            new String[] { Long.class.getName(), Long.class.getName() },
1634                            RecentLayoutSetBranchModelImpl.USERID_COLUMN_BITMASK |
1635                            RecentLayoutSetBranchModelImpl.LAYOUTSETID_COLUMN_BITMASK);
1636            public static final FinderPath FINDER_PATH_COUNT_BY_U_L = new FinderPath(RecentLayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
1637                            RecentLayoutSetBranchModelImpl.FINDER_CACHE_ENABLED, Long.class,
1638                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_L",
1639                            new String[] { Long.class.getName(), Long.class.getName() });
1640    
1641            /**
1642             * Returns the recent layout set branch where userId = &#63; and layoutSetId = &#63; or throws a {@link NoSuchRecentLayoutSetBranchException} if it could not be found.
1643             *
1644             * @param userId the user ID
1645             * @param layoutSetId the layout set ID
1646             * @return the matching recent layout set branch
1647             * @throws NoSuchRecentLayoutSetBranchException if a matching recent layout set branch could not be found
1648             */
1649            @Override
1650            public RecentLayoutSetBranch findByU_L(long userId, long layoutSetId)
1651                    throws NoSuchRecentLayoutSetBranchException {
1652                    RecentLayoutSetBranch recentLayoutSetBranch = fetchByU_L(userId,
1653                                    layoutSetId);
1654    
1655                    if (recentLayoutSetBranch == null) {
1656                            StringBundler msg = new StringBundler(6);
1657    
1658                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1659    
1660                            msg.append("userId=");
1661                            msg.append(userId);
1662    
1663                            msg.append(", layoutSetId=");
1664                            msg.append(layoutSetId);
1665    
1666                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1667    
1668                            if (_log.isWarnEnabled()) {
1669                                    _log.warn(msg.toString());
1670                            }
1671    
1672                            throw new NoSuchRecentLayoutSetBranchException(msg.toString());
1673                    }
1674    
1675                    return recentLayoutSetBranch;
1676            }
1677    
1678            /**
1679             * Returns the recent layout set branch where userId = &#63; and layoutSetId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
1680             *
1681             * @param userId the user ID
1682             * @param layoutSetId the layout set ID
1683             * @return the matching recent layout set branch, or <code>null</code> if a matching recent layout set branch could not be found
1684             */
1685            @Override
1686            public RecentLayoutSetBranch fetchByU_L(long userId, long layoutSetId) {
1687                    return fetchByU_L(userId, layoutSetId, true);
1688            }
1689    
1690            /**
1691             * Returns the recent layout set branch where userId = &#63; and layoutSetId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
1692             *
1693             * @param userId the user ID
1694             * @param layoutSetId the layout set ID
1695             * @param retrieveFromCache whether to retrieve from the finder cache
1696             * @return the matching recent layout set branch, or <code>null</code> if a matching recent layout set branch could not be found
1697             */
1698            @Override
1699            public RecentLayoutSetBranch fetchByU_L(long userId, long layoutSetId,
1700                    boolean retrieveFromCache) {
1701                    Object[] finderArgs = new Object[] { userId, layoutSetId };
1702    
1703                    Object result = null;
1704    
1705                    if (retrieveFromCache) {
1706                            result = finderCache.getResult(FINDER_PATH_FETCH_BY_U_L,
1707                                            finderArgs, this);
1708                    }
1709    
1710                    if (result instanceof RecentLayoutSetBranch) {
1711                            RecentLayoutSetBranch recentLayoutSetBranch = (RecentLayoutSetBranch)result;
1712    
1713                            if ((userId != recentLayoutSetBranch.getUserId()) ||
1714                                            (layoutSetId != recentLayoutSetBranch.getLayoutSetId())) {
1715                                    result = null;
1716                            }
1717                    }
1718    
1719                    if (result == null) {
1720                            StringBundler query = new StringBundler(4);
1721    
1722                            query.append(_SQL_SELECT_RECENTLAYOUTSETBRANCH_WHERE);
1723    
1724                            query.append(_FINDER_COLUMN_U_L_USERID_2);
1725    
1726                            query.append(_FINDER_COLUMN_U_L_LAYOUTSETID_2);
1727    
1728                            String sql = query.toString();
1729    
1730                            Session session = null;
1731    
1732                            try {
1733                                    session = openSession();
1734    
1735                                    Query q = session.createQuery(sql);
1736    
1737                                    QueryPos qPos = QueryPos.getInstance(q);
1738    
1739                                    qPos.add(userId);
1740    
1741                                    qPos.add(layoutSetId);
1742    
1743                                    List<RecentLayoutSetBranch> list = q.list();
1744    
1745                                    if (list.isEmpty()) {
1746                                            finderCache.putResult(FINDER_PATH_FETCH_BY_U_L, finderArgs,
1747                                                    list);
1748                                    }
1749                                    else {
1750                                            RecentLayoutSetBranch recentLayoutSetBranch = list.get(0);
1751    
1752                                            result = recentLayoutSetBranch;
1753    
1754                                            cacheResult(recentLayoutSetBranch);
1755    
1756                                            if ((recentLayoutSetBranch.getUserId() != userId) ||
1757                                                            (recentLayoutSetBranch.getLayoutSetId() != layoutSetId)) {
1758                                                    finderCache.putResult(FINDER_PATH_FETCH_BY_U_L,
1759                                                            finderArgs, recentLayoutSetBranch);
1760                                            }
1761                                    }
1762                            }
1763                            catch (Exception e) {
1764                                    finderCache.removeResult(FINDER_PATH_FETCH_BY_U_L, finderArgs);
1765    
1766                                    throw processException(e);
1767                            }
1768                            finally {
1769                                    closeSession(session);
1770                            }
1771                    }
1772    
1773                    if (result instanceof List<?>) {
1774                            return null;
1775                    }
1776                    else {
1777                            return (RecentLayoutSetBranch)result;
1778                    }
1779            }
1780    
1781            /**
1782             * Removes the recent layout set branch where userId = &#63; and layoutSetId = &#63; from the database.
1783             *
1784             * @param userId the user ID
1785             * @param layoutSetId the layout set ID
1786             * @return the recent layout set branch that was removed
1787             */
1788            @Override
1789            public RecentLayoutSetBranch removeByU_L(long userId, long layoutSetId)
1790                    throws NoSuchRecentLayoutSetBranchException {
1791                    RecentLayoutSetBranch recentLayoutSetBranch = findByU_L(userId,
1792                                    layoutSetId);
1793    
1794                    return remove(recentLayoutSetBranch);
1795            }
1796    
1797            /**
1798             * Returns the number of recent layout set branchs where userId = &#63; and layoutSetId = &#63;.
1799             *
1800             * @param userId the user ID
1801             * @param layoutSetId the layout set ID
1802             * @return the number of matching recent layout set branchs
1803             */
1804            @Override
1805            public int countByU_L(long userId, long layoutSetId) {
1806                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_L;
1807    
1808                    Object[] finderArgs = new Object[] { userId, layoutSetId };
1809    
1810                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1811    
1812                    if (count == null) {
1813                            StringBundler query = new StringBundler(3);
1814    
1815                            query.append(_SQL_COUNT_RECENTLAYOUTSETBRANCH_WHERE);
1816    
1817                            query.append(_FINDER_COLUMN_U_L_USERID_2);
1818    
1819                            query.append(_FINDER_COLUMN_U_L_LAYOUTSETID_2);
1820    
1821                            String sql = query.toString();
1822    
1823                            Session session = null;
1824    
1825                            try {
1826                                    session = openSession();
1827    
1828                                    Query q = session.createQuery(sql);
1829    
1830                                    QueryPos qPos = QueryPos.getInstance(q);
1831    
1832                                    qPos.add(userId);
1833    
1834                                    qPos.add(layoutSetId);
1835    
1836                                    count = (Long)q.uniqueResult();
1837    
1838                                    finderCache.putResult(finderPath, finderArgs, count);
1839                            }
1840                            catch (Exception e) {
1841                                    finderCache.removeResult(finderPath, finderArgs);
1842    
1843                                    throw processException(e);
1844                            }
1845                            finally {
1846                                    closeSession(session);
1847                            }
1848                    }
1849    
1850                    return count.intValue();
1851            }
1852    
1853            private static final String _FINDER_COLUMN_U_L_USERID_2 = "recentLayoutSetBranch.userId = ? AND ";
1854            private static final String _FINDER_COLUMN_U_L_LAYOUTSETID_2 = "recentLayoutSetBranch.layoutSetId = ?";
1855    
1856            public RecentLayoutSetBranchPersistenceImpl() {
1857                    setModelClass(RecentLayoutSetBranch.class);
1858            }
1859    
1860            /**
1861             * Caches the recent layout set branch in the entity cache if it is enabled.
1862             *
1863             * @param recentLayoutSetBranch the recent layout set branch
1864             */
1865            @Override
1866            public void cacheResult(RecentLayoutSetBranch recentLayoutSetBranch) {
1867                    entityCache.putResult(RecentLayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
1868                            RecentLayoutSetBranchImpl.class,
1869                            recentLayoutSetBranch.getPrimaryKey(), recentLayoutSetBranch);
1870    
1871                    finderCache.putResult(FINDER_PATH_FETCH_BY_U_L,
1872                            new Object[] {
1873                                    recentLayoutSetBranch.getUserId(),
1874                                    recentLayoutSetBranch.getLayoutSetId()
1875                            }, recentLayoutSetBranch);
1876    
1877                    recentLayoutSetBranch.resetOriginalValues();
1878            }
1879    
1880            /**
1881             * Caches the recent layout set branchs in the entity cache if it is enabled.
1882             *
1883             * @param recentLayoutSetBranchs the recent layout set branchs
1884             */
1885            @Override
1886            public void cacheResult(List<RecentLayoutSetBranch> recentLayoutSetBranchs) {
1887                    for (RecentLayoutSetBranch recentLayoutSetBranch : recentLayoutSetBranchs) {
1888                            if (entityCache.getResult(
1889                                                    RecentLayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
1890                                                    RecentLayoutSetBranchImpl.class,
1891                                                    recentLayoutSetBranch.getPrimaryKey()) == null) {
1892                                    cacheResult(recentLayoutSetBranch);
1893                            }
1894                            else {
1895                                    recentLayoutSetBranch.resetOriginalValues();
1896                            }
1897                    }
1898            }
1899    
1900            /**
1901             * Clears the cache for all recent layout set branchs.
1902             *
1903             * <p>
1904             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
1905             * </p>
1906             */
1907            @Override
1908            public void clearCache() {
1909                    entityCache.clearCache(RecentLayoutSetBranchImpl.class);
1910    
1911                    finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
1912                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1913                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1914            }
1915    
1916            /**
1917             * Clears the cache for the recent layout set branch.
1918             *
1919             * <p>
1920             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
1921             * </p>
1922             */
1923            @Override
1924            public void clearCache(RecentLayoutSetBranch recentLayoutSetBranch) {
1925                    entityCache.removeResult(RecentLayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
1926                            RecentLayoutSetBranchImpl.class,
1927                            recentLayoutSetBranch.getPrimaryKey());
1928    
1929                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1930                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1931    
1932                    clearUniqueFindersCache((RecentLayoutSetBranchModelImpl)recentLayoutSetBranch);
1933            }
1934    
1935            @Override
1936            public void clearCache(List<RecentLayoutSetBranch> recentLayoutSetBranchs) {
1937                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1938                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1939    
1940                    for (RecentLayoutSetBranch recentLayoutSetBranch : recentLayoutSetBranchs) {
1941                            entityCache.removeResult(RecentLayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
1942                                    RecentLayoutSetBranchImpl.class,
1943                                    recentLayoutSetBranch.getPrimaryKey());
1944    
1945                            clearUniqueFindersCache((RecentLayoutSetBranchModelImpl)recentLayoutSetBranch);
1946                    }
1947            }
1948    
1949            protected void cacheUniqueFindersCache(
1950                    RecentLayoutSetBranchModelImpl recentLayoutSetBranchModelImpl,
1951                    boolean isNew) {
1952                    if (isNew) {
1953                            Object[] args = new Object[] {
1954                                            recentLayoutSetBranchModelImpl.getUserId(),
1955                                            recentLayoutSetBranchModelImpl.getLayoutSetId()
1956                                    };
1957    
1958                            finderCache.putResult(FINDER_PATH_COUNT_BY_U_L, args,
1959                                    Long.valueOf(1));
1960                            finderCache.putResult(FINDER_PATH_FETCH_BY_U_L, args,
1961                                    recentLayoutSetBranchModelImpl);
1962                    }
1963                    else {
1964                            if ((recentLayoutSetBranchModelImpl.getColumnBitmask() &
1965                                            FINDER_PATH_FETCH_BY_U_L.getColumnBitmask()) != 0) {
1966                                    Object[] args = new Object[] {
1967                                                    recentLayoutSetBranchModelImpl.getUserId(),
1968                                                    recentLayoutSetBranchModelImpl.getLayoutSetId()
1969                                            };
1970    
1971                                    finderCache.putResult(FINDER_PATH_COUNT_BY_U_L, args,
1972                                            Long.valueOf(1));
1973                                    finderCache.putResult(FINDER_PATH_FETCH_BY_U_L, args,
1974                                            recentLayoutSetBranchModelImpl);
1975                            }
1976                    }
1977            }
1978    
1979            protected void clearUniqueFindersCache(
1980                    RecentLayoutSetBranchModelImpl recentLayoutSetBranchModelImpl) {
1981                    Object[] args = new Object[] {
1982                                    recentLayoutSetBranchModelImpl.getUserId(),
1983                                    recentLayoutSetBranchModelImpl.getLayoutSetId()
1984                            };
1985    
1986                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_L, args);
1987                    finderCache.removeResult(FINDER_PATH_FETCH_BY_U_L, args);
1988    
1989                    if ((recentLayoutSetBranchModelImpl.getColumnBitmask() &
1990                                    FINDER_PATH_FETCH_BY_U_L.getColumnBitmask()) != 0) {
1991                            args = new Object[] {
1992                                            recentLayoutSetBranchModelImpl.getOriginalUserId(),
1993                                            recentLayoutSetBranchModelImpl.getOriginalLayoutSetId()
1994                                    };
1995    
1996                            finderCache.removeResult(FINDER_PATH_COUNT_BY_U_L, args);
1997                            finderCache.removeResult(FINDER_PATH_FETCH_BY_U_L, args);
1998                    }
1999            }
2000    
2001            /**
2002             * Creates a new recent layout set branch with the primary key. Does not add the recent layout set branch to the database.
2003             *
2004             * @param recentLayoutSetBranchId the primary key for the new recent layout set branch
2005             * @return the new recent layout set branch
2006             */
2007            @Override
2008            public RecentLayoutSetBranch create(long recentLayoutSetBranchId) {
2009                    RecentLayoutSetBranch recentLayoutSetBranch = new RecentLayoutSetBranchImpl();
2010    
2011                    recentLayoutSetBranch.setNew(true);
2012                    recentLayoutSetBranch.setPrimaryKey(recentLayoutSetBranchId);
2013    
2014                    recentLayoutSetBranch.setCompanyId(companyProvider.getCompanyId());
2015    
2016                    return recentLayoutSetBranch;
2017            }
2018    
2019            /**
2020             * Removes the recent layout set branch with the primary key from the database. Also notifies the appropriate model listeners.
2021             *
2022             * @param recentLayoutSetBranchId the primary key of the recent layout set branch
2023             * @return the recent layout set branch that was removed
2024             * @throws NoSuchRecentLayoutSetBranchException if a recent layout set branch with the primary key could not be found
2025             */
2026            @Override
2027            public RecentLayoutSetBranch remove(long recentLayoutSetBranchId)
2028                    throws NoSuchRecentLayoutSetBranchException {
2029                    return remove((Serializable)recentLayoutSetBranchId);
2030            }
2031    
2032            /**
2033             * Removes the recent layout set branch with the primary key from the database. Also notifies the appropriate model listeners.
2034             *
2035             * @param primaryKey the primary key of the recent layout set branch
2036             * @return the recent layout set branch that was removed
2037             * @throws NoSuchRecentLayoutSetBranchException if a recent layout set branch with the primary key could not be found
2038             */
2039            @Override
2040            public RecentLayoutSetBranch remove(Serializable primaryKey)
2041                    throws NoSuchRecentLayoutSetBranchException {
2042                    Session session = null;
2043    
2044                    try {
2045                            session = openSession();
2046    
2047                            RecentLayoutSetBranch recentLayoutSetBranch = (RecentLayoutSetBranch)session.get(RecentLayoutSetBranchImpl.class,
2048                                            primaryKey);
2049    
2050                            if (recentLayoutSetBranch == null) {
2051                                    if (_log.isWarnEnabled()) {
2052                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2053                                    }
2054    
2055                                    throw new NoSuchRecentLayoutSetBranchException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2056                                            primaryKey);
2057                            }
2058    
2059                            return remove(recentLayoutSetBranch);
2060                    }
2061                    catch (NoSuchRecentLayoutSetBranchException nsee) {
2062                            throw nsee;
2063                    }
2064                    catch (Exception e) {
2065                            throw processException(e);
2066                    }
2067                    finally {
2068                            closeSession(session);
2069                    }
2070            }
2071    
2072            @Override
2073            protected RecentLayoutSetBranch removeImpl(
2074                    RecentLayoutSetBranch recentLayoutSetBranch) {
2075                    recentLayoutSetBranch = toUnwrappedModel(recentLayoutSetBranch);
2076    
2077                    Session session = null;
2078    
2079                    try {
2080                            session = openSession();
2081    
2082                            if (!session.contains(recentLayoutSetBranch)) {
2083                                    recentLayoutSetBranch = (RecentLayoutSetBranch)session.get(RecentLayoutSetBranchImpl.class,
2084                                                    recentLayoutSetBranch.getPrimaryKeyObj());
2085                            }
2086    
2087                            if (recentLayoutSetBranch != null) {
2088                                    session.delete(recentLayoutSetBranch);
2089                            }
2090                    }
2091                    catch (Exception e) {
2092                            throw processException(e);
2093                    }
2094                    finally {
2095                            closeSession(session);
2096                    }
2097    
2098                    if (recentLayoutSetBranch != null) {
2099                            clearCache(recentLayoutSetBranch);
2100                    }
2101    
2102                    return recentLayoutSetBranch;
2103            }
2104    
2105            @Override
2106            public RecentLayoutSetBranch updateImpl(
2107                    RecentLayoutSetBranch recentLayoutSetBranch) {
2108                    recentLayoutSetBranch = toUnwrappedModel(recentLayoutSetBranch);
2109    
2110                    boolean isNew = recentLayoutSetBranch.isNew();
2111    
2112                    RecentLayoutSetBranchModelImpl recentLayoutSetBranchModelImpl = (RecentLayoutSetBranchModelImpl)recentLayoutSetBranch;
2113    
2114                    Session session = null;
2115    
2116                    try {
2117                            session = openSession();
2118    
2119                            if (recentLayoutSetBranch.isNew()) {
2120                                    session.save(recentLayoutSetBranch);
2121    
2122                                    recentLayoutSetBranch.setNew(false);
2123                            }
2124                            else {
2125                                    recentLayoutSetBranch = (RecentLayoutSetBranch)session.merge(recentLayoutSetBranch);
2126                            }
2127                    }
2128                    catch (Exception e) {
2129                            throw processException(e);
2130                    }
2131                    finally {
2132                            closeSession(session);
2133                    }
2134    
2135                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2136    
2137                    if (isNew || !RecentLayoutSetBranchModelImpl.COLUMN_BITMASK_ENABLED) {
2138                            finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2139                    }
2140    
2141                    else {
2142                            if ((recentLayoutSetBranchModelImpl.getColumnBitmask() &
2143                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
2144                                    Object[] args = new Object[] {
2145                                                    recentLayoutSetBranchModelImpl.getOriginalGroupId()
2146                                            };
2147    
2148                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
2149                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
2150                                            args);
2151    
2152                                    args = new Object[] { recentLayoutSetBranchModelImpl.getGroupId() };
2153    
2154                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
2155                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
2156                                            args);
2157                            }
2158    
2159                            if ((recentLayoutSetBranchModelImpl.getColumnBitmask() &
2160                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
2161                                    Object[] args = new Object[] {
2162                                                    recentLayoutSetBranchModelImpl.getOriginalUserId()
2163                                            };
2164    
2165                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
2166                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
2167                                            args);
2168    
2169                                    args = new Object[] { recentLayoutSetBranchModelImpl.getUserId() };
2170    
2171                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
2172                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
2173                                            args);
2174                            }
2175    
2176                            if ((recentLayoutSetBranchModelImpl.getColumnBitmask() &
2177                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LAYOUTSETBRANCHID.getColumnBitmask()) != 0) {
2178                                    Object[] args = new Object[] {
2179                                                    recentLayoutSetBranchModelImpl.getOriginalLayoutSetBranchId()
2180                                            };
2181    
2182                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_LAYOUTSETBRANCHID,
2183                                            args);
2184                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LAYOUTSETBRANCHID,
2185                                            args);
2186    
2187                                    args = new Object[] {
2188                                                    recentLayoutSetBranchModelImpl.getLayoutSetBranchId()
2189                                            };
2190    
2191                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_LAYOUTSETBRANCHID,
2192                                            args);
2193                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LAYOUTSETBRANCHID,
2194                                            args);
2195                            }
2196                    }
2197    
2198                    entityCache.putResult(RecentLayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
2199                            RecentLayoutSetBranchImpl.class,
2200                            recentLayoutSetBranch.getPrimaryKey(), recentLayoutSetBranch, false);
2201    
2202                    clearUniqueFindersCache(recentLayoutSetBranchModelImpl);
2203                    cacheUniqueFindersCache(recentLayoutSetBranchModelImpl, isNew);
2204    
2205                    recentLayoutSetBranch.resetOriginalValues();
2206    
2207                    return recentLayoutSetBranch;
2208            }
2209    
2210            protected RecentLayoutSetBranch toUnwrappedModel(
2211                    RecentLayoutSetBranch recentLayoutSetBranch) {
2212                    if (recentLayoutSetBranch instanceof RecentLayoutSetBranchImpl) {
2213                            return recentLayoutSetBranch;
2214                    }
2215    
2216                    RecentLayoutSetBranchImpl recentLayoutSetBranchImpl = new RecentLayoutSetBranchImpl();
2217    
2218                    recentLayoutSetBranchImpl.setNew(recentLayoutSetBranch.isNew());
2219                    recentLayoutSetBranchImpl.setPrimaryKey(recentLayoutSetBranch.getPrimaryKey());
2220    
2221                    recentLayoutSetBranchImpl.setMvccVersion(recentLayoutSetBranch.getMvccVersion());
2222                    recentLayoutSetBranchImpl.setRecentLayoutSetBranchId(recentLayoutSetBranch.getRecentLayoutSetBranchId());
2223                    recentLayoutSetBranchImpl.setGroupId(recentLayoutSetBranch.getGroupId());
2224                    recentLayoutSetBranchImpl.setCompanyId(recentLayoutSetBranch.getCompanyId());
2225                    recentLayoutSetBranchImpl.setUserId(recentLayoutSetBranch.getUserId());
2226                    recentLayoutSetBranchImpl.setLayoutSetBranchId(recentLayoutSetBranch.getLayoutSetBranchId());
2227                    recentLayoutSetBranchImpl.setLayoutSetId(recentLayoutSetBranch.getLayoutSetId());
2228    
2229                    return recentLayoutSetBranchImpl;
2230            }
2231    
2232            /**
2233             * Returns the recent layout set branch with the primary key or throws a {@link com.liferay.portal.exception.NoSuchModelException} if it could not be found.
2234             *
2235             * @param primaryKey the primary key of the recent layout set branch
2236             * @return the recent layout set branch
2237             * @throws NoSuchRecentLayoutSetBranchException if a recent layout set branch with the primary key could not be found
2238             */
2239            @Override
2240            public RecentLayoutSetBranch findByPrimaryKey(Serializable primaryKey)
2241                    throws NoSuchRecentLayoutSetBranchException {
2242                    RecentLayoutSetBranch recentLayoutSetBranch = fetchByPrimaryKey(primaryKey);
2243    
2244                    if (recentLayoutSetBranch == null) {
2245                            if (_log.isWarnEnabled()) {
2246                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2247                            }
2248    
2249                            throw new NoSuchRecentLayoutSetBranchException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2250                                    primaryKey);
2251                    }
2252    
2253                    return recentLayoutSetBranch;
2254            }
2255    
2256            /**
2257             * Returns the recent layout set branch with the primary key or throws a {@link NoSuchRecentLayoutSetBranchException} if it could not be found.
2258             *
2259             * @param recentLayoutSetBranchId the primary key of the recent layout set branch
2260             * @return the recent layout set branch
2261             * @throws NoSuchRecentLayoutSetBranchException if a recent layout set branch with the primary key could not be found
2262             */
2263            @Override
2264            public RecentLayoutSetBranch findByPrimaryKey(long recentLayoutSetBranchId)
2265                    throws NoSuchRecentLayoutSetBranchException {
2266                    return findByPrimaryKey((Serializable)recentLayoutSetBranchId);
2267            }
2268    
2269            /**
2270             * Returns the recent layout set branch with the primary key or returns <code>null</code> if it could not be found.
2271             *
2272             * @param primaryKey the primary key of the recent layout set branch
2273             * @return the recent layout set branch, or <code>null</code> if a recent layout set branch with the primary key could not be found
2274             */
2275            @Override
2276            public RecentLayoutSetBranch fetchByPrimaryKey(Serializable primaryKey) {
2277                    RecentLayoutSetBranch recentLayoutSetBranch = (RecentLayoutSetBranch)entityCache.getResult(RecentLayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
2278                                    RecentLayoutSetBranchImpl.class, primaryKey);
2279    
2280                    if (recentLayoutSetBranch == _nullRecentLayoutSetBranch) {
2281                            return null;
2282                    }
2283    
2284                    if (recentLayoutSetBranch == null) {
2285                            Session session = null;
2286    
2287                            try {
2288                                    session = openSession();
2289    
2290                                    recentLayoutSetBranch = (RecentLayoutSetBranch)session.get(RecentLayoutSetBranchImpl.class,
2291                                                    primaryKey);
2292    
2293                                    if (recentLayoutSetBranch != null) {
2294                                            cacheResult(recentLayoutSetBranch);
2295                                    }
2296                                    else {
2297                                            entityCache.putResult(RecentLayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
2298                                                    RecentLayoutSetBranchImpl.class, primaryKey,
2299                                                    _nullRecentLayoutSetBranch);
2300                                    }
2301                            }
2302                            catch (Exception e) {
2303                                    entityCache.removeResult(RecentLayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
2304                                            RecentLayoutSetBranchImpl.class, primaryKey);
2305    
2306                                    throw processException(e);
2307                            }
2308                            finally {
2309                                    closeSession(session);
2310                            }
2311                    }
2312    
2313                    return recentLayoutSetBranch;
2314            }
2315    
2316            /**
2317             * Returns the recent layout set branch with the primary key or returns <code>null</code> if it could not be found.
2318             *
2319             * @param recentLayoutSetBranchId the primary key of the recent layout set branch
2320             * @return the recent layout set branch, or <code>null</code> if a recent layout set branch with the primary key could not be found
2321             */
2322            @Override
2323            public RecentLayoutSetBranch fetchByPrimaryKey(long recentLayoutSetBranchId) {
2324                    return fetchByPrimaryKey((Serializable)recentLayoutSetBranchId);
2325            }
2326    
2327            @Override
2328            public Map<Serializable, RecentLayoutSetBranch> fetchByPrimaryKeys(
2329                    Set<Serializable> primaryKeys) {
2330                    if (primaryKeys.isEmpty()) {
2331                            return Collections.emptyMap();
2332                    }
2333    
2334                    Map<Serializable, RecentLayoutSetBranch> map = new HashMap<Serializable, RecentLayoutSetBranch>();
2335    
2336                    if (primaryKeys.size() == 1) {
2337                            Iterator<Serializable> iterator = primaryKeys.iterator();
2338    
2339                            Serializable primaryKey = iterator.next();
2340    
2341                            RecentLayoutSetBranch recentLayoutSetBranch = fetchByPrimaryKey(primaryKey);
2342    
2343                            if (recentLayoutSetBranch != null) {
2344                                    map.put(primaryKey, recentLayoutSetBranch);
2345                            }
2346    
2347                            return map;
2348                    }
2349    
2350                    Set<Serializable> uncachedPrimaryKeys = null;
2351    
2352                    for (Serializable primaryKey : primaryKeys) {
2353                            RecentLayoutSetBranch recentLayoutSetBranch = (RecentLayoutSetBranch)entityCache.getResult(RecentLayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
2354                                            RecentLayoutSetBranchImpl.class, primaryKey);
2355    
2356                            if (recentLayoutSetBranch == null) {
2357                                    if (uncachedPrimaryKeys == null) {
2358                                            uncachedPrimaryKeys = new HashSet<Serializable>();
2359                                    }
2360    
2361                                    uncachedPrimaryKeys.add(primaryKey);
2362                            }
2363                            else {
2364                                    map.put(primaryKey, recentLayoutSetBranch);
2365                            }
2366                    }
2367    
2368                    if (uncachedPrimaryKeys == null) {
2369                            return map;
2370                    }
2371    
2372                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
2373                                    1);
2374    
2375                    query.append(_SQL_SELECT_RECENTLAYOUTSETBRANCH_WHERE_PKS_IN);
2376    
2377                    for (Serializable primaryKey : uncachedPrimaryKeys) {
2378                            query.append(String.valueOf(primaryKey));
2379    
2380                            query.append(StringPool.COMMA);
2381                    }
2382    
2383                    query.setIndex(query.index() - 1);
2384    
2385                    query.append(StringPool.CLOSE_PARENTHESIS);
2386    
2387                    String sql = query.toString();
2388    
2389                    Session session = null;
2390    
2391                    try {
2392                            session = openSession();
2393    
2394                            Query q = session.createQuery(sql);
2395    
2396                            for (RecentLayoutSetBranch recentLayoutSetBranch : (List<RecentLayoutSetBranch>)q.list()) {
2397                                    map.put(recentLayoutSetBranch.getPrimaryKeyObj(),
2398                                            recentLayoutSetBranch);
2399    
2400                                    cacheResult(recentLayoutSetBranch);
2401    
2402                                    uncachedPrimaryKeys.remove(recentLayoutSetBranch.getPrimaryKeyObj());
2403                            }
2404    
2405                            for (Serializable primaryKey : uncachedPrimaryKeys) {
2406                                    entityCache.putResult(RecentLayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
2407                                            RecentLayoutSetBranchImpl.class, primaryKey,
2408                                            _nullRecentLayoutSetBranch);
2409                            }
2410                    }
2411                    catch (Exception e) {
2412                            throw processException(e);
2413                    }
2414                    finally {
2415                            closeSession(session);
2416                    }
2417    
2418                    return map;
2419            }
2420    
2421            /**
2422             * Returns all the recent layout set branchs.
2423             *
2424             * @return the recent layout set branchs
2425             */
2426            @Override
2427            public List<RecentLayoutSetBranch> findAll() {
2428                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2429            }
2430    
2431            /**
2432             * Returns a range of all the recent layout set branchs.
2433             *
2434             * <p>
2435             * 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 RecentLayoutSetBranchModelImpl}. 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.
2436             * </p>
2437             *
2438             * @param start the lower bound of the range of recent layout set branchs
2439             * @param end the upper bound of the range of recent layout set branchs (not inclusive)
2440             * @return the range of recent layout set branchs
2441             */
2442            @Override
2443            public List<RecentLayoutSetBranch> findAll(int start, int end) {
2444                    return findAll(start, end, null);
2445            }
2446    
2447            /**
2448             * Returns an ordered range of all the recent layout set branchs.
2449             *
2450             * <p>
2451             * 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 RecentLayoutSetBranchModelImpl}. 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.
2452             * </p>
2453             *
2454             * @param start the lower bound of the range of recent layout set branchs
2455             * @param end the upper bound of the range of recent layout set branchs (not inclusive)
2456             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2457             * @return the ordered range of recent layout set branchs
2458             */
2459            @Override
2460            public List<RecentLayoutSetBranch> findAll(int start, int end,
2461                    OrderByComparator<RecentLayoutSetBranch> orderByComparator) {
2462                    return findAll(start, end, orderByComparator, true);
2463            }
2464    
2465            /**
2466             * Returns an ordered range of all the recent layout set branchs.
2467             *
2468             * <p>
2469             * 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 RecentLayoutSetBranchModelImpl}. 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.
2470             * </p>
2471             *
2472             * @param start the lower bound of the range of recent layout set branchs
2473             * @param end the upper bound of the range of recent layout set branchs (not inclusive)
2474             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2475             * @param retrieveFromCache whether to retrieve from the finder cache
2476             * @return the ordered range of recent layout set branchs
2477             */
2478            @Override
2479            public List<RecentLayoutSetBranch> findAll(int start, int end,
2480                    OrderByComparator<RecentLayoutSetBranch> orderByComparator,
2481                    boolean retrieveFromCache) {
2482                    boolean pagination = true;
2483                    FinderPath finderPath = null;
2484                    Object[] finderArgs = null;
2485    
2486                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2487                                    (orderByComparator == null)) {
2488                            pagination = false;
2489                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2490                            finderArgs = FINDER_ARGS_EMPTY;
2491                    }
2492                    else {
2493                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2494                            finderArgs = new Object[] { start, end, orderByComparator };
2495                    }
2496    
2497                    List<RecentLayoutSetBranch> list = null;
2498    
2499                    if (retrieveFromCache) {
2500                            list = (List<RecentLayoutSetBranch>)finderCache.getResult(finderPath,
2501                                            finderArgs, this);
2502                    }
2503    
2504                    if (list == null) {
2505                            StringBundler query = null;
2506                            String sql = null;
2507    
2508                            if (orderByComparator != null) {
2509                                    query = new StringBundler(2 +
2510                                                    (orderByComparator.getOrderByFields().length * 3));
2511    
2512                                    query.append(_SQL_SELECT_RECENTLAYOUTSETBRANCH);
2513    
2514                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2515                                            orderByComparator);
2516    
2517                                    sql = query.toString();
2518                            }
2519                            else {
2520                                    sql = _SQL_SELECT_RECENTLAYOUTSETBRANCH;
2521    
2522                                    if (pagination) {
2523                                            sql = sql.concat(RecentLayoutSetBranchModelImpl.ORDER_BY_JPQL);
2524                                    }
2525                            }
2526    
2527                            Session session = null;
2528    
2529                            try {
2530                                    session = openSession();
2531    
2532                                    Query q = session.createQuery(sql);
2533    
2534                                    if (!pagination) {
2535                                            list = (List<RecentLayoutSetBranch>)QueryUtil.list(q,
2536                                                            getDialect(), start, end, false);
2537    
2538                                            Collections.sort(list);
2539    
2540                                            list = Collections.unmodifiableList(list);
2541                                    }
2542                                    else {
2543                                            list = (List<RecentLayoutSetBranch>)QueryUtil.list(q,
2544                                                            getDialect(), start, end);
2545                                    }
2546    
2547                                    cacheResult(list);
2548    
2549                                    finderCache.putResult(finderPath, finderArgs, list);
2550                            }
2551                            catch (Exception e) {
2552                                    finderCache.removeResult(finderPath, finderArgs);
2553    
2554                                    throw processException(e);
2555                            }
2556                            finally {
2557                                    closeSession(session);
2558                            }
2559                    }
2560    
2561                    return list;
2562            }
2563    
2564            /**
2565             * Removes all the recent layout set branchs from the database.
2566             *
2567             */
2568            @Override
2569            public void removeAll() {
2570                    for (RecentLayoutSetBranch recentLayoutSetBranch : findAll()) {
2571                            remove(recentLayoutSetBranch);
2572                    }
2573            }
2574    
2575            /**
2576             * Returns the number of recent layout set branchs.
2577             *
2578             * @return the number of recent layout set branchs
2579             */
2580            @Override
2581            public int countAll() {
2582                    Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
2583                                    FINDER_ARGS_EMPTY, this);
2584    
2585                    if (count == null) {
2586                            Session session = null;
2587    
2588                            try {
2589                                    session = openSession();
2590    
2591                                    Query q = session.createQuery(_SQL_COUNT_RECENTLAYOUTSETBRANCH);
2592    
2593                                    count = (Long)q.uniqueResult();
2594    
2595                                    finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
2596                                            count);
2597                            }
2598                            catch (Exception e) {
2599                                    finderCache.removeResult(FINDER_PATH_COUNT_ALL,
2600                                            FINDER_ARGS_EMPTY);
2601    
2602                                    throw processException(e);
2603                            }
2604                            finally {
2605                                    closeSession(session);
2606                            }
2607                    }
2608    
2609                    return count.intValue();
2610            }
2611    
2612            @Override
2613            protected Map<String, Integer> getTableColumnsMap() {
2614                    return RecentLayoutSetBranchModelImpl.TABLE_COLUMNS_MAP;
2615            }
2616    
2617            /**
2618             * Initializes the recent layout set branch persistence.
2619             */
2620            public void afterPropertiesSet() {
2621            }
2622    
2623            public void destroy() {
2624                    entityCache.removeCache(RecentLayoutSetBranchImpl.class.getName());
2625                    finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
2626                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2627                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2628            }
2629    
2630            @BeanReference(type = CompanyProviderWrapper.class)
2631            protected CompanyProvider companyProvider;
2632            protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
2633            protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
2634            private static final String _SQL_SELECT_RECENTLAYOUTSETBRANCH = "SELECT recentLayoutSetBranch FROM RecentLayoutSetBranch recentLayoutSetBranch";
2635            private static final String _SQL_SELECT_RECENTLAYOUTSETBRANCH_WHERE_PKS_IN = "SELECT recentLayoutSetBranch FROM RecentLayoutSetBranch recentLayoutSetBranch WHERE recentLayoutSetBranchId IN (";
2636            private static final String _SQL_SELECT_RECENTLAYOUTSETBRANCH_WHERE = "SELECT recentLayoutSetBranch FROM RecentLayoutSetBranch recentLayoutSetBranch WHERE ";
2637            private static final String _SQL_COUNT_RECENTLAYOUTSETBRANCH = "SELECT COUNT(recentLayoutSetBranch) FROM RecentLayoutSetBranch recentLayoutSetBranch";
2638            private static final String _SQL_COUNT_RECENTLAYOUTSETBRANCH_WHERE = "SELECT COUNT(recentLayoutSetBranch) FROM RecentLayoutSetBranch recentLayoutSetBranch WHERE ";
2639            private static final String _ORDER_BY_ENTITY_ALIAS = "recentLayoutSetBranch.";
2640            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No RecentLayoutSetBranch exists with the primary key ";
2641            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No RecentLayoutSetBranch exists with the key {";
2642            private static final Log _log = LogFactoryUtil.getLog(RecentLayoutSetBranchPersistenceImpl.class);
2643            private static final RecentLayoutSetBranch _nullRecentLayoutSetBranch = new RecentLayoutSetBranchImpl() {
2644                            @Override
2645                            public Object clone() {
2646                                    return this;
2647                            }
2648    
2649                            @Override
2650                            public CacheModel<RecentLayoutSetBranch> toCacheModel() {
2651                                    return _nullRecentLayoutSetBranchCacheModel;
2652                            }
2653                    };
2654    
2655            private static final CacheModel<RecentLayoutSetBranch> _nullRecentLayoutSetBranchCacheModel =
2656                    new NullCacheModel();
2657    
2658            private static class NullCacheModel implements CacheModel<RecentLayoutSetBranch>,
2659                    MVCCModel {
2660                    @Override
2661                    public long getMvccVersion() {
2662                            return -1;
2663                    }
2664    
2665                    @Override
2666                    public void setMvccVersion(long mvccVersion) {
2667                    }
2668    
2669                    @Override
2670                    public RecentLayoutSetBranch toEntityModel() {
2671                            return _nullRecentLayoutSetBranch;
2672                    }
2673            }
2674    }