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