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