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