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