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