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