001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.service.persistence.impl;
016    
017    import aQute.bnd.annotation.ProviderType;
018    
019    import com.liferay.portal.kernel.bean.BeanReference;
020    import com.liferay.portal.kernel.dao.orm.EntityCache;
021    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderCache;
023    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
024    import com.liferay.portal.kernel.dao.orm.FinderPath;
025    import com.liferay.portal.kernel.dao.orm.Query;
026    import com.liferay.portal.kernel.dao.orm.QueryPos;
027    import com.liferay.portal.kernel.dao.orm.QueryUtil;
028    import com.liferay.portal.kernel.dao.orm.Session;
029    import com.liferay.portal.kernel.exception.NoSuchLayoutFriendlyURLException;
030    import com.liferay.portal.kernel.log.Log;
031    import com.liferay.portal.kernel.log.LogFactoryUtil;
032    import com.liferay.portal.kernel.model.CacheModel;
033    import com.liferay.portal.kernel.model.LayoutFriendlyURL;
034    import com.liferay.portal.kernel.model.MVCCModel;
035    import com.liferay.portal.kernel.service.ServiceContext;
036    import com.liferay.portal.kernel.service.ServiceContextThreadLocal;
037    import com.liferay.portal.kernel.service.persistence.CompanyProvider;
038    import com.liferay.portal.kernel.service.persistence.CompanyProviderWrapper;
039    import com.liferay.portal.kernel.service.persistence.LayoutFriendlyURLPersistence;
040    import com.liferay.portal.kernel.service.persistence.impl.BasePersistenceImpl;
041    import com.liferay.portal.kernel.util.OrderByComparator;
042    import com.liferay.portal.kernel.util.SetUtil;
043    import com.liferay.portal.kernel.util.StringBundler;
044    import com.liferay.portal.kernel.util.StringPool;
045    import com.liferay.portal.kernel.util.Validator;
046    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
047    import com.liferay.portal.model.impl.LayoutFriendlyURLImpl;
048    import com.liferay.portal.model.impl.LayoutFriendlyURLModelImpl;
049    
050    import java.io.Serializable;
051    
052    import java.util.Collections;
053    import java.util.Date;
054    import java.util.HashMap;
055    import java.util.HashSet;
056    import java.util.Iterator;
057    import java.util.List;
058    import java.util.Map;
059    import java.util.Objects;
060    import java.util.Set;
061    
062    /**
063     * The persistence implementation for the layout friendly u r l service.
064     *
065     * <p>
066     * Caching information and settings can be found in <code>portal.properties</code>
067     * </p>
068     *
069     * @author Brian Wing Shun Chan
070     * @see LayoutFriendlyURLPersistence
071     * @see com.liferay.portal.kernel.service.persistence.LayoutFriendlyURLUtil
072     * @generated
073     */
074    @ProviderType
075    public class LayoutFriendlyURLPersistenceImpl extends BasePersistenceImpl<LayoutFriendlyURL>
076            implements LayoutFriendlyURLPersistence {
077            /*
078             * NOTE FOR DEVELOPERS:
079             *
080             * Never modify or reference this class directly. Always use {@link LayoutFriendlyURLUtil} to access the layout friendly u r l persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
081             */
082            public static final String FINDER_CLASS_NAME_ENTITY = LayoutFriendlyURLImpl.class.getName();
083            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
084                    ".List1";
085            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
086                    ".List2";
087            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(LayoutFriendlyURLModelImpl.ENTITY_CACHE_ENABLED,
088                            LayoutFriendlyURLModelImpl.FINDER_CACHE_ENABLED,
089                            LayoutFriendlyURLImpl.class,
090                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
091            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(LayoutFriendlyURLModelImpl.ENTITY_CACHE_ENABLED,
092                            LayoutFriendlyURLModelImpl.FINDER_CACHE_ENABLED,
093                            LayoutFriendlyURLImpl.class,
094                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
095            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(LayoutFriendlyURLModelImpl.ENTITY_CACHE_ENABLED,
096                            LayoutFriendlyURLModelImpl.FINDER_CACHE_ENABLED, Long.class,
097                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
098            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(LayoutFriendlyURLModelImpl.ENTITY_CACHE_ENABLED,
099                            LayoutFriendlyURLModelImpl.FINDER_CACHE_ENABLED,
100                            LayoutFriendlyURLImpl.class,
101                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
102                            new String[] {
103                                    String.class.getName(),
104                                    
105                            Integer.class.getName(), Integer.class.getName(),
106                                    OrderByComparator.class.getName()
107                            });
108            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(LayoutFriendlyURLModelImpl.ENTITY_CACHE_ENABLED,
109                            LayoutFriendlyURLModelImpl.FINDER_CACHE_ENABLED,
110                            LayoutFriendlyURLImpl.class,
111                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
112                            new String[] { String.class.getName() },
113                            LayoutFriendlyURLModelImpl.UUID_COLUMN_BITMASK);
114            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(LayoutFriendlyURLModelImpl.ENTITY_CACHE_ENABLED,
115                            LayoutFriendlyURLModelImpl.FINDER_CACHE_ENABLED, Long.class,
116                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
117                            new String[] { String.class.getName() });
118    
119            /**
120             * Returns all the layout friendly u r ls where uuid = &#63;.
121             *
122             * @param uuid the uuid
123             * @return the matching layout friendly u r ls
124             */
125            @Override
126            public List<LayoutFriendlyURL> findByUuid(String uuid) {
127                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
128            }
129    
130            /**
131             * Returns a range of all the layout friendly u r ls where uuid = &#63;.
132             *
133             * <p>
134             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link LayoutFriendlyURLModelImpl}. 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.
135             * </p>
136             *
137             * @param uuid the uuid
138             * @param start the lower bound of the range of layout friendly u r ls
139             * @param end the upper bound of the range of layout friendly u r ls (not inclusive)
140             * @return the range of matching layout friendly u r ls
141             */
142            @Override
143            public List<LayoutFriendlyURL> findByUuid(String uuid, int start, int end) {
144                    return findByUuid(uuid, start, end, null);
145            }
146    
147            /**
148             * Returns an ordered range of all the layout friendly u r ls where uuid = &#63;.
149             *
150             * <p>
151             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link LayoutFriendlyURLModelImpl}. 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.
152             * </p>
153             *
154             * @param uuid the uuid
155             * @param start the lower bound of the range of layout friendly u r ls
156             * @param end the upper bound of the range of layout friendly u r ls (not inclusive)
157             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
158             * @return the ordered range of matching layout friendly u r ls
159             */
160            @Override
161            public List<LayoutFriendlyURL> findByUuid(String uuid, int start, int end,
162                    OrderByComparator<LayoutFriendlyURL> orderByComparator) {
163                    return findByUuid(uuid, start, end, orderByComparator, true);
164            }
165    
166            /**
167             * Returns an ordered range of all the layout friendly u r ls where uuid = &#63;.
168             *
169             * <p>
170             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link LayoutFriendlyURLModelImpl}. 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.
171             * </p>
172             *
173             * @param uuid the uuid
174             * @param start the lower bound of the range of layout friendly u r ls
175             * @param end the upper bound of the range of layout friendly u r ls (not inclusive)
176             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
177             * @param retrieveFromCache whether to retrieve from the finder cache
178             * @return the ordered range of matching layout friendly u r ls
179             */
180            @Override
181            public List<LayoutFriendlyURL> findByUuid(String uuid, int start, int end,
182                    OrderByComparator<LayoutFriendlyURL> orderByComparator,
183                    boolean retrieveFromCache) {
184                    boolean pagination = true;
185                    FinderPath finderPath = null;
186                    Object[] finderArgs = null;
187    
188                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
189                                    (orderByComparator == null)) {
190                            pagination = false;
191                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
192                            finderArgs = new Object[] { uuid };
193                    }
194                    else {
195                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
196                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
197                    }
198    
199                    List<LayoutFriendlyURL> list = null;
200    
201                    if (retrieveFromCache) {
202                            list = (List<LayoutFriendlyURL>)finderCache.getResult(finderPath,
203                                            finderArgs, this);
204    
205                            if ((list != null) && !list.isEmpty()) {
206                                    for (LayoutFriendlyURL layoutFriendlyURL : list) {
207                                            if (!Objects.equals(uuid, layoutFriendlyURL.getUuid())) {
208                                                    list = null;
209    
210                                                    break;
211                                            }
212                                    }
213                            }
214                    }
215    
216                    if (list == null) {
217                            StringBundler query = null;
218    
219                            if (orderByComparator != null) {
220                                    query = new StringBundler(3 +
221                                                    (orderByComparator.getOrderByFields().length * 2));
222                            }
223                            else {
224                                    query = new StringBundler(3);
225                            }
226    
227                            query.append(_SQL_SELECT_LAYOUTFRIENDLYURL_WHERE);
228    
229                            boolean bindUuid = false;
230    
231                            if (uuid == null) {
232                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
233                            }
234                            else if (uuid.equals(StringPool.BLANK)) {
235                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
236                            }
237                            else {
238                                    bindUuid = true;
239    
240                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
241                            }
242    
243                            if (orderByComparator != null) {
244                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
245                                            orderByComparator);
246                            }
247                            else
248                             if (pagination) {
249                                    query.append(LayoutFriendlyURLModelImpl.ORDER_BY_JPQL);
250                            }
251    
252                            String sql = query.toString();
253    
254                            Session session = null;
255    
256                            try {
257                                    session = openSession();
258    
259                                    Query q = session.createQuery(sql);
260    
261                                    QueryPos qPos = QueryPos.getInstance(q);
262    
263                                    if (bindUuid) {
264                                            qPos.add(uuid);
265                                    }
266    
267                                    if (!pagination) {
268                                            list = (List<LayoutFriendlyURL>)QueryUtil.list(q,
269                                                            getDialect(), start, end, false);
270    
271                                            Collections.sort(list);
272    
273                                            list = Collections.unmodifiableList(list);
274                                    }
275                                    else {
276                                            list = (List<LayoutFriendlyURL>)QueryUtil.list(q,
277                                                            getDialect(), start, end);
278                                    }
279    
280                                    cacheResult(list);
281    
282                                    finderCache.putResult(finderPath, finderArgs, list);
283                            }
284                            catch (Exception e) {
285                                    finderCache.removeResult(finderPath, finderArgs);
286    
287                                    throw processException(e);
288                            }
289                            finally {
290                                    closeSession(session);
291                            }
292                    }
293    
294                    return list;
295            }
296    
297            /**
298             * Returns the first layout friendly u r l in the ordered set where uuid = &#63;.
299             *
300             * @param uuid the uuid
301             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
302             * @return the first matching layout friendly u r l
303             * @throws NoSuchLayoutFriendlyURLException if a matching layout friendly u r l could not be found
304             */
305            @Override
306            public LayoutFriendlyURL findByUuid_First(String uuid,
307                    OrderByComparator<LayoutFriendlyURL> orderByComparator)
308                    throws NoSuchLayoutFriendlyURLException {
309                    LayoutFriendlyURL layoutFriendlyURL = fetchByUuid_First(uuid,
310                                    orderByComparator);
311    
312                    if (layoutFriendlyURL != null) {
313                            return layoutFriendlyURL;
314                    }
315    
316                    StringBundler msg = new StringBundler(4);
317    
318                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
319    
320                    msg.append("uuid=");
321                    msg.append(uuid);
322    
323                    msg.append(StringPool.CLOSE_CURLY_BRACE);
324    
325                    throw new NoSuchLayoutFriendlyURLException(msg.toString());
326            }
327    
328            /**
329             * Returns the first layout friendly u r l in the ordered set where uuid = &#63;.
330             *
331             * @param uuid the uuid
332             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
333             * @return the first matching layout friendly u r l, or <code>null</code> if a matching layout friendly u r l could not be found
334             */
335            @Override
336            public LayoutFriendlyURL fetchByUuid_First(String uuid,
337                    OrderByComparator<LayoutFriendlyURL> orderByComparator) {
338                    List<LayoutFriendlyURL> list = findByUuid(uuid, 0, 1, orderByComparator);
339    
340                    if (!list.isEmpty()) {
341                            return list.get(0);
342                    }
343    
344                    return null;
345            }
346    
347            /**
348             * Returns the last layout friendly u r l in the ordered set where uuid = &#63;.
349             *
350             * @param uuid the uuid
351             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
352             * @return the last matching layout friendly u r l
353             * @throws NoSuchLayoutFriendlyURLException if a matching layout friendly u r l could not be found
354             */
355            @Override
356            public LayoutFriendlyURL findByUuid_Last(String uuid,
357                    OrderByComparator<LayoutFriendlyURL> orderByComparator)
358                    throws NoSuchLayoutFriendlyURLException {
359                    LayoutFriendlyURL layoutFriendlyURL = fetchByUuid_Last(uuid,
360                                    orderByComparator);
361    
362                    if (layoutFriendlyURL != null) {
363                            return layoutFriendlyURL;
364                    }
365    
366                    StringBundler msg = new StringBundler(4);
367    
368                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
369    
370                    msg.append("uuid=");
371                    msg.append(uuid);
372    
373                    msg.append(StringPool.CLOSE_CURLY_BRACE);
374    
375                    throw new NoSuchLayoutFriendlyURLException(msg.toString());
376            }
377    
378            /**
379             * Returns the last layout friendly u r l in the ordered set where uuid = &#63;.
380             *
381             * @param uuid the uuid
382             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
383             * @return the last matching layout friendly u r l, or <code>null</code> if a matching layout friendly u r l could not be found
384             */
385            @Override
386            public LayoutFriendlyURL fetchByUuid_Last(String uuid,
387                    OrderByComparator<LayoutFriendlyURL> orderByComparator) {
388                    int count = countByUuid(uuid);
389    
390                    if (count == 0) {
391                            return null;
392                    }
393    
394                    List<LayoutFriendlyURL> list = findByUuid(uuid, count - 1, count,
395                                    orderByComparator);
396    
397                    if (!list.isEmpty()) {
398                            return list.get(0);
399                    }
400    
401                    return null;
402            }
403    
404            /**
405             * Returns the layout friendly u r ls before and after the current layout friendly u r l in the ordered set where uuid = &#63;.
406             *
407             * @param layoutFriendlyURLId the primary key of the current layout friendly u r l
408             * @param uuid the uuid
409             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
410             * @return the previous, current, and next layout friendly u r l
411             * @throws NoSuchLayoutFriendlyURLException if a layout friendly u r l with the primary key could not be found
412             */
413            @Override
414            public LayoutFriendlyURL[] findByUuid_PrevAndNext(
415                    long layoutFriendlyURLId, String uuid,
416                    OrderByComparator<LayoutFriendlyURL> orderByComparator)
417                    throws NoSuchLayoutFriendlyURLException {
418                    LayoutFriendlyURL layoutFriendlyURL = findByPrimaryKey(layoutFriendlyURLId);
419    
420                    Session session = null;
421    
422                    try {
423                            session = openSession();
424    
425                            LayoutFriendlyURL[] array = new LayoutFriendlyURLImpl[3];
426    
427                            array[0] = getByUuid_PrevAndNext(session, layoutFriendlyURL, uuid,
428                                            orderByComparator, true);
429    
430                            array[1] = layoutFriendlyURL;
431    
432                            array[2] = getByUuid_PrevAndNext(session, layoutFriendlyURL, uuid,
433                                            orderByComparator, false);
434    
435                            return array;
436                    }
437                    catch (Exception e) {
438                            throw processException(e);
439                    }
440                    finally {
441                            closeSession(session);
442                    }
443            }
444    
445            protected LayoutFriendlyURL getByUuid_PrevAndNext(Session session,
446                    LayoutFriendlyURL layoutFriendlyURL, String uuid,
447                    OrderByComparator<LayoutFriendlyURL> orderByComparator, boolean previous) {
448                    StringBundler query = null;
449    
450                    if (orderByComparator != null) {
451                            query = new StringBundler(4 +
452                                            (orderByComparator.getOrderByConditionFields().length * 3) +
453                                            (orderByComparator.getOrderByFields().length * 3));
454                    }
455                    else {
456                            query = new StringBundler(3);
457                    }
458    
459                    query.append(_SQL_SELECT_LAYOUTFRIENDLYURL_WHERE);
460    
461                    boolean bindUuid = false;
462    
463                    if (uuid == null) {
464                            query.append(_FINDER_COLUMN_UUID_UUID_1);
465                    }
466                    else if (uuid.equals(StringPool.BLANK)) {
467                            query.append(_FINDER_COLUMN_UUID_UUID_3);
468                    }
469                    else {
470                            bindUuid = true;
471    
472                            query.append(_FINDER_COLUMN_UUID_UUID_2);
473                    }
474    
475                    if (orderByComparator != null) {
476                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
477    
478                            if (orderByConditionFields.length > 0) {
479                                    query.append(WHERE_AND);
480                            }
481    
482                            for (int i = 0; i < orderByConditionFields.length; i++) {
483                                    query.append(_ORDER_BY_ENTITY_ALIAS);
484                                    query.append(orderByConditionFields[i]);
485    
486                                    if ((i + 1) < orderByConditionFields.length) {
487                                            if (orderByComparator.isAscending() ^ previous) {
488                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
489                                            }
490                                            else {
491                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
492                                            }
493                                    }
494                                    else {
495                                            if (orderByComparator.isAscending() ^ previous) {
496                                                    query.append(WHERE_GREATER_THAN);
497                                            }
498                                            else {
499                                                    query.append(WHERE_LESSER_THAN);
500                                            }
501                                    }
502                            }
503    
504                            query.append(ORDER_BY_CLAUSE);
505    
506                            String[] orderByFields = orderByComparator.getOrderByFields();
507    
508                            for (int i = 0; i < orderByFields.length; i++) {
509                                    query.append(_ORDER_BY_ENTITY_ALIAS);
510                                    query.append(orderByFields[i]);
511    
512                                    if ((i + 1) < orderByFields.length) {
513                                            if (orderByComparator.isAscending() ^ previous) {
514                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
515                                            }
516                                            else {
517                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
518                                            }
519                                    }
520                                    else {
521                                            if (orderByComparator.isAscending() ^ previous) {
522                                                    query.append(ORDER_BY_ASC);
523                                            }
524                                            else {
525                                                    query.append(ORDER_BY_DESC);
526                                            }
527                                    }
528                            }
529                    }
530                    else {
531                            query.append(LayoutFriendlyURLModelImpl.ORDER_BY_JPQL);
532                    }
533    
534                    String sql = query.toString();
535    
536                    Query q = session.createQuery(sql);
537    
538                    q.setFirstResult(0);
539                    q.setMaxResults(2);
540    
541                    QueryPos qPos = QueryPos.getInstance(q);
542    
543                    if (bindUuid) {
544                            qPos.add(uuid);
545                    }
546    
547                    if (orderByComparator != null) {
548                            Object[] values = orderByComparator.getOrderByConditionValues(layoutFriendlyURL);
549    
550                            for (Object value : values) {
551                                    qPos.add(value);
552                            }
553                    }
554    
555                    List<LayoutFriendlyURL> list = q.list();
556    
557                    if (list.size() == 2) {
558                            return list.get(1);
559                    }
560                    else {
561                            return null;
562                    }
563            }
564    
565            /**
566             * Removes all the layout friendly u r ls where uuid = &#63; from the database.
567             *
568             * @param uuid the uuid
569             */
570            @Override
571            public void removeByUuid(String uuid) {
572                    for (LayoutFriendlyURL layoutFriendlyURL : findByUuid(uuid,
573                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
574                            remove(layoutFriendlyURL);
575                    }
576            }
577    
578            /**
579             * Returns the number of layout friendly u r ls where uuid = &#63;.
580             *
581             * @param uuid the uuid
582             * @return the number of matching layout friendly u r ls
583             */
584            @Override
585            public int countByUuid(String uuid) {
586                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
587    
588                    Object[] finderArgs = new Object[] { uuid };
589    
590                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
591    
592                    if (count == null) {
593                            StringBundler query = new StringBundler(2);
594    
595                            query.append(_SQL_COUNT_LAYOUTFRIENDLYURL_WHERE);
596    
597                            boolean bindUuid = false;
598    
599                            if (uuid == null) {
600                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
601                            }
602                            else if (uuid.equals(StringPool.BLANK)) {
603                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
604                            }
605                            else {
606                                    bindUuid = true;
607    
608                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
609                            }
610    
611                            String sql = query.toString();
612    
613                            Session session = null;
614    
615                            try {
616                                    session = openSession();
617    
618                                    Query q = session.createQuery(sql);
619    
620                                    QueryPos qPos = QueryPos.getInstance(q);
621    
622                                    if (bindUuid) {
623                                            qPos.add(uuid);
624                                    }
625    
626                                    count = (Long)q.uniqueResult();
627    
628                                    finderCache.putResult(finderPath, finderArgs, count);
629                            }
630                            catch (Exception e) {
631                                    finderCache.removeResult(finderPath, finderArgs);
632    
633                                    throw processException(e);
634                            }
635                            finally {
636                                    closeSession(session);
637                            }
638                    }
639    
640                    return count.intValue();
641            }
642    
643            private static final String _FINDER_COLUMN_UUID_UUID_1 = "layoutFriendlyURL.uuid IS NULL";
644            private static final String _FINDER_COLUMN_UUID_UUID_2 = "layoutFriendlyURL.uuid = ?";
645            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(layoutFriendlyURL.uuid IS NULL OR layoutFriendlyURL.uuid = '')";
646            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(LayoutFriendlyURLModelImpl.ENTITY_CACHE_ENABLED,
647                            LayoutFriendlyURLModelImpl.FINDER_CACHE_ENABLED,
648                            LayoutFriendlyURLImpl.class, FINDER_CLASS_NAME_ENTITY,
649                            "fetchByUUID_G",
650                            new String[] { String.class.getName(), Long.class.getName() },
651                            LayoutFriendlyURLModelImpl.UUID_COLUMN_BITMASK |
652                            LayoutFriendlyURLModelImpl.GROUPID_COLUMN_BITMASK);
653            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(LayoutFriendlyURLModelImpl.ENTITY_CACHE_ENABLED,
654                            LayoutFriendlyURLModelImpl.FINDER_CACHE_ENABLED, Long.class,
655                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
656                            new String[] { String.class.getName(), Long.class.getName() });
657    
658            /**
659             * Returns the layout friendly u r l where uuid = &#63; and groupId = &#63; or throws a {@link NoSuchLayoutFriendlyURLException} if it could not be found.
660             *
661             * @param uuid the uuid
662             * @param groupId the group ID
663             * @return the matching layout friendly u r l
664             * @throws NoSuchLayoutFriendlyURLException if a matching layout friendly u r l could not be found
665             */
666            @Override
667            public LayoutFriendlyURL findByUUID_G(String uuid, long groupId)
668                    throws NoSuchLayoutFriendlyURLException {
669                    LayoutFriendlyURL layoutFriendlyURL = fetchByUUID_G(uuid, groupId);
670    
671                    if (layoutFriendlyURL == null) {
672                            StringBundler msg = new StringBundler(6);
673    
674                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
675    
676                            msg.append("uuid=");
677                            msg.append(uuid);
678    
679                            msg.append(", groupId=");
680                            msg.append(groupId);
681    
682                            msg.append(StringPool.CLOSE_CURLY_BRACE);
683    
684                            if (_log.isDebugEnabled()) {
685                                    _log.debug(msg.toString());
686                            }
687    
688                            throw new NoSuchLayoutFriendlyURLException(msg.toString());
689                    }
690    
691                    return layoutFriendlyURL;
692            }
693    
694            /**
695             * Returns the layout friendly u r l where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
696             *
697             * @param uuid the uuid
698             * @param groupId the group ID
699             * @return the matching layout friendly u r l, or <code>null</code> if a matching layout friendly u r l could not be found
700             */
701            @Override
702            public LayoutFriendlyURL fetchByUUID_G(String uuid, long groupId) {
703                    return fetchByUUID_G(uuid, groupId, true);
704            }
705    
706            /**
707             * Returns the layout friendly u r l where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
708             *
709             * @param uuid the uuid
710             * @param groupId the group ID
711             * @param retrieveFromCache whether to retrieve from the finder cache
712             * @return the matching layout friendly u r l, or <code>null</code> if a matching layout friendly u r l could not be found
713             */
714            @Override
715            public LayoutFriendlyURL fetchByUUID_G(String uuid, long groupId,
716                    boolean retrieveFromCache) {
717                    Object[] finderArgs = new Object[] { uuid, groupId };
718    
719                    Object result = null;
720    
721                    if (retrieveFromCache) {
722                            result = finderCache.getResult(FINDER_PATH_FETCH_BY_UUID_G,
723                                            finderArgs, this);
724                    }
725    
726                    if (result instanceof LayoutFriendlyURL) {
727                            LayoutFriendlyURL layoutFriendlyURL = (LayoutFriendlyURL)result;
728    
729                            if (!Objects.equals(uuid, layoutFriendlyURL.getUuid()) ||
730                                            (groupId != layoutFriendlyURL.getGroupId())) {
731                                    result = null;
732                            }
733                    }
734    
735                    if (result == null) {
736                            StringBundler query = new StringBundler(4);
737    
738                            query.append(_SQL_SELECT_LAYOUTFRIENDLYURL_WHERE);
739    
740                            boolean bindUuid = false;
741    
742                            if (uuid == null) {
743                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
744                            }
745                            else if (uuid.equals(StringPool.BLANK)) {
746                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
747                            }
748                            else {
749                                    bindUuid = true;
750    
751                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
752                            }
753    
754                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
755    
756                            String sql = query.toString();
757    
758                            Session session = null;
759    
760                            try {
761                                    session = openSession();
762    
763                                    Query q = session.createQuery(sql);
764    
765                                    QueryPos qPos = QueryPos.getInstance(q);
766    
767                                    if (bindUuid) {
768                                            qPos.add(uuid);
769                                    }
770    
771                                    qPos.add(groupId);
772    
773                                    List<LayoutFriendlyURL> list = q.list();
774    
775                                    if (list.isEmpty()) {
776                                            finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G,
777                                                    finderArgs, list);
778                                    }
779                                    else {
780                                            LayoutFriendlyURL layoutFriendlyURL = list.get(0);
781    
782                                            result = layoutFriendlyURL;
783    
784                                            cacheResult(layoutFriendlyURL);
785    
786                                            if ((layoutFriendlyURL.getUuid() == null) ||
787                                                            !layoutFriendlyURL.getUuid().equals(uuid) ||
788                                                            (layoutFriendlyURL.getGroupId() != groupId)) {
789                                                    finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G,
790                                                            finderArgs, layoutFriendlyURL);
791                                            }
792                                    }
793                            }
794                            catch (Exception e) {
795                                    finderCache.removeResult(FINDER_PATH_FETCH_BY_UUID_G, finderArgs);
796    
797                                    throw processException(e);
798                            }
799                            finally {
800                                    closeSession(session);
801                            }
802                    }
803    
804                    if (result instanceof List<?>) {
805                            return null;
806                    }
807                    else {
808                            return (LayoutFriendlyURL)result;
809                    }
810            }
811    
812            /**
813             * Removes the layout friendly u r l where uuid = &#63; and groupId = &#63; from the database.
814             *
815             * @param uuid the uuid
816             * @param groupId the group ID
817             * @return the layout friendly u r l that was removed
818             */
819            @Override
820            public LayoutFriendlyURL removeByUUID_G(String uuid, long groupId)
821                    throws NoSuchLayoutFriendlyURLException {
822                    LayoutFriendlyURL layoutFriendlyURL = findByUUID_G(uuid, groupId);
823    
824                    return remove(layoutFriendlyURL);
825            }
826    
827            /**
828             * Returns the number of layout friendly u r ls where uuid = &#63; and groupId = &#63;.
829             *
830             * @param uuid the uuid
831             * @param groupId the group ID
832             * @return the number of matching layout friendly u r ls
833             */
834            @Override
835            public int countByUUID_G(String uuid, long groupId) {
836                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G;
837    
838                    Object[] finderArgs = new Object[] { uuid, groupId };
839    
840                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
841    
842                    if (count == null) {
843                            StringBundler query = new StringBundler(3);
844    
845                            query.append(_SQL_COUNT_LAYOUTFRIENDLYURL_WHERE);
846    
847                            boolean bindUuid = false;
848    
849                            if (uuid == null) {
850                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
851                            }
852                            else if (uuid.equals(StringPool.BLANK)) {
853                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
854                            }
855                            else {
856                                    bindUuid = true;
857    
858                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
859                            }
860    
861                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
862    
863                            String sql = query.toString();
864    
865                            Session session = null;
866    
867                            try {
868                                    session = openSession();
869    
870                                    Query q = session.createQuery(sql);
871    
872                                    QueryPos qPos = QueryPos.getInstance(q);
873    
874                                    if (bindUuid) {
875                                            qPos.add(uuid);
876                                    }
877    
878                                    qPos.add(groupId);
879    
880                                    count = (Long)q.uniqueResult();
881    
882                                    finderCache.putResult(finderPath, finderArgs, count);
883                            }
884                            catch (Exception e) {
885                                    finderCache.removeResult(finderPath, finderArgs);
886    
887                                    throw processException(e);
888                            }
889                            finally {
890                                    closeSession(session);
891                            }
892                    }
893    
894                    return count.intValue();
895            }
896    
897            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "layoutFriendlyURL.uuid IS NULL AND ";
898            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "layoutFriendlyURL.uuid = ? AND ";
899            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(layoutFriendlyURL.uuid IS NULL OR layoutFriendlyURL.uuid = '') AND ";
900            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "layoutFriendlyURL.groupId = ?";
901            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(LayoutFriendlyURLModelImpl.ENTITY_CACHE_ENABLED,
902                            LayoutFriendlyURLModelImpl.FINDER_CACHE_ENABLED,
903                            LayoutFriendlyURLImpl.class,
904                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
905                            new String[] {
906                                    String.class.getName(), Long.class.getName(),
907                                    
908                            Integer.class.getName(), Integer.class.getName(),
909                                    OrderByComparator.class.getName()
910                            });
911            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
912                    new FinderPath(LayoutFriendlyURLModelImpl.ENTITY_CACHE_ENABLED,
913                            LayoutFriendlyURLModelImpl.FINDER_CACHE_ENABLED,
914                            LayoutFriendlyURLImpl.class,
915                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
916                            new String[] { String.class.getName(), Long.class.getName() },
917                            LayoutFriendlyURLModelImpl.UUID_COLUMN_BITMASK |
918                            LayoutFriendlyURLModelImpl.COMPANYID_COLUMN_BITMASK);
919            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(LayoutFriendlyURLModelImpl.ENTITY_CACHE_ENABLED,
920                            LayoutFriendlyURLModelImpl.FINDER_CACHE_ENABLED, Long.class,
921                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
922                            new String[] { String.class.getName(), Long.class.getName() });
923    
924            /**
925             * Returns all the layout friendly u r ls where uuid = &#63; and companyId = &#63;.
926             *
927             * @param uuid the uuid
928             * @param companyId the company ID
929             * @return the matching layout friendly u r ls
930             */
931            @Override
932            public List<LayoutFriendlyURL> findByUuid_C(String uuid, long companyId) {
933                    return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
934                            QueryUtil.ALL_POS, null);
935            }
936    
937            /**
938             * Returns a range of all the layout friendly u r ls where uuid = &#63; and companyId = &#63;.
939             *
940             * <p>
941             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link LayoutFriendlyURLModelImpl}. 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.
942             * </p>
943             *
944             * @param uuid the uuid
945             * @param companyId the company ID
946             * @param start the lower bound of the range of layout friendly u r ls
947             * @param end the upper bound of the range of layout friendly u r ls (not inclusive)
948             * @return the range of matching layout friendly u r ls
949             */
950            @Override
951            public List<LayoutFriendlyURL> findByUuid_C(String uuid, long companyId,
952                    int start, int end) {
953                    return findByUuid_C(uuid, companyId, start, end, null);
954            }
955    
956            /**
957             * Returns an ordered range of all the layout friendly u r ls where uuid = &#63; and companyId = &#63;.
958             *
959             * <p>
960             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link LayoutFriendlyURLModelImpl}. 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.
961             * </p>
962             *
963             * @param uuid the uuid
964             * @param companyId the company ID
965             * @param start the lower bound of the range of layout friendly u r ls
966             * @param end the upper bound of the range of layout friendly u r ls (not inclusive)
967             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
968             * @return the ordered range of matching layout friendly u r ls
969             */
970            @Override
971            public List<LayoutFriendlyURL> findByUuid_C(String uuid, long companyId,
972                    int start, int end,
973                    OrderByComparator<LayoutFriendlyURL> orderByComparator) {
974                    return findByUuid_C(uuid, companyId, start, end, orderByComparator, true);
975            }
976    
977            /**
978             * Returns an ordered range of all the layout friendly u r ls where uuid = &#63; and companyId = &#63;.
979             *
980             * <p>
981             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link LayoutFriendlyURLModelImpl}. 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.
982             * </p>
983             *
984             * @param uuid the uuid
985             * @param companyId the company ID
986             * @param start the lower bound of the range of layout friendly u r ls
987             * @param end the upper bound of the range of layout friendly u r ls (not inclusive)
988             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
989             * @param retrieveFromCache whether to retrieve from the finder cache
990             * @return the ordered range of matching layout friendly u r ls
991             */
992            @Override
993            public List<LayoutFriendlyURL> findByUuid_C(String uuid, long companyId,
994                    int start, int end,
995                    OrderByComparator<LayoutFriendlyURL> orderByComparator,
996                    boolean retrieveFromCache) {
997                    boolean pagination = true;
998                    FinderPath finderPath = null;
999                    Object[] finderArgs = null;
1000    
1001                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1002                                    (orderByComparator == null)) {
1003                            pagination = false;
1004                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
1005                            finderArgs = new Object[] { uuid, companyId };
1006                    }
1007                    else {
1008                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
1009                            finderArgs = new Object[] {
1010                                            uuid, companyId,
1011                                            
1012                                            start, end, orderByComparator
1013                                    };
1014                    }
1015    
1016                    List<LayoutFriendlyURL> list = null;
1017    
1018                    if (retrieveFromCache) {
1019                            list = (List<LayoutFriendlyURL>)finderCache.getResult(finderPath,
1020                                            finderArgs, this);
1021    
1022                            if ((list != null) && !list.isEmpty()) {
1023                                    for (LayoutFriendlyURL layoutFriendlyURL : list) {
1024                                            if (!Objects.equals(uuid, layoutFriendlyURL.getUuid()) ||
1025                                                            (companyId != layoutFriendlyURL.getCompanyId())) {
1026                                                    list = null;
1027    
1028                                                    break;
1029                                            }
1030                                    }
1031                            }
1032                    }
1033    
1034                    if (list == null) {
1035                            StringBundler query = null;
1036    
1037                            if (orderByComparator != null) {
1038                                    query = new StringBundler(4 +
1039                                                    (orderByComparator.getOrderByFields().length * 2));
1040                            }
1041                            else {
1042                                    query = new StringBundler(4);
1043                            }
1044    
1045                            query.append(_SQL_SELECT_LAYOUTFRIENDLYURL_WHERE);
1046    
1047                            boolean bindUuid = false;
1048    
1049                            if (uuid == null) {
1050                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1051                            }
1052                            else if (uuid.equals(StringPool.BLANK)) {
1053                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1054                            }
1055                            else {
1056                                    bindUuid = true;
1057    
1058                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1059                            }
1060    
1061                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1062    
1063                            if (orderByComparator != null) {
1064                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1065                                            orderByComparator);
1066                            }
1067                            else
1068                             if (pagination) {
1069                                    query.append(LayoutFriendlyURLModelImpl.ORDER_BY_JPQL);
1070                            }
1071    
1072                            String sql = query.toString();
1073    
1074                            Session session = null;
1075    
1076                            try {
1077                                    session = openSession();
1078    
1079                                    Query q = session.createQuery(sql);
1080    
1081                                    QueryPos qPos = QueryPos.getInstance(q);
1082    
1083                                    if (bindUuid) {
1084                                            qPos.add(uuid);
1085                                    }
1086    
1087                                    qPos.add(companyId);
1088    
1089                                    if (!pagination) {
1090                                            list = (List<LayoutFriendlyURL>)QueryUtil.list(q,
1091                                                            getDialect(), start, end, false);
1092    
1093                                            Collections.sort(list);
1094    
1095                                            list = Collections.unmodifiableList(list);
1096                                    }
1097                                    else {
1098                                            list = (List<LayoutFriendlyURL>)QueryUtil.list(q,
1099                                                            getDialect(), start, end);
1100                                    }
1101    
1102                                    cacheResult(list);
1103    
1104                                    finderCache.putResult(finderPath, finderArgs, list);
1105                            }
1106                            catch (Exception e) {
1107                                    finderCache.removeResult(finderPath, finderArgs);
1108    
1109                                    throw processException(e);
1110                            }
1111                            finally {
1112                                    closeSession(session);
1113                            }
1114                    }
1115    
1116                    return list;
1117            }
1118    
1119            /**
1120             * Returns the first layout friendly u r l in the ordered set where uuid = &#63; and companyId = &#63;.
1121             *
1122             * @param uuid the uuid
1123             * @param companyId the company ID
1124             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1125             * @return the first matching layout friendly u r l
1126             * @throws NoSuchLayoutFriendlyURLException if a matching layout friendly u r l could not be found
1127             */
1128            @Override
1129            public LayoutFriendlyURL findByUuid_C_First(String uuid, long companyId,
1130                    OrderByComparator<LayoutFriendlyURL> orderByComparator)
1131                    throws NoSuchLayoutFriendlyURLException {
1132                    LayoutFriendlyURL layoutFriendlyURL = fetchByUuid_C_First(uuid,
1133                                    companyId, orderByComparator);
1134    
1135                    if (layoutFriendlyURL != null) {
1136                            return layoutFriendlyURL;
1137                    }
1138    
1139                    StringBundler msg = new StringBundler(6);
1140    
1141                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1142    
1143                    msg.append("uuid=");
1144                    msg.append(uuid);
1145    
1146                    msg.append(", companyId=");
1147                    msg.append(companyId);
1148    
1149                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1150    
1151                    throw new NoSuchLayoutFriendlyURLException(msg.toString());
1152            }
1153    
1154            /**
1155             * Returns the first layout friendly u r l in the ordered set where uuid = &#63; and companyId = &#63;.
1156             *
1157             * @param uuid the uuid
1158             * @param companyId the company ID
1159             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1160             * @return the first matching layout friendly u r l, or <code>null</code> if a matching layout friendly u r l could not be found
1161             */
1162            @Override
1163            public LayoutFriendlyURL fetchByUuid_C_First(String uuid, long companyId,
1164                    OrderByComparator<LayoutFriendlyURL> orderByComparator) {
1165                    List<LayoutFriendlyURL> list = findByUuid_C(uuid, companyId, 0, 1,
1166                                    orderByComparator);
1167    
1168                    if (!list.isEmpty()) {
1169                            return list.get(0);
1170                    }
1171    
1172                    return null;
1173            }
1174    
1175            /**
1176             * Returns the last layout friendly u r l in the ordered set where uuid = &#63; and companyId = &#63;.
1177             *
1178             * @param uuid the uuid
1179             * @param companyId the company ID
1180             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1181             * @return the last matching layout friendly u r l
1182             * @throws NoSuchLayoutFriendlyURLException if a matching layout friendly u r l could not be found
1183             */
1184            @Override
1185            public LayoutFriendlyURL findByUuid_C_Last(String uuid, long companyId,
1186                    OrderByComparator<LayoutFriendlyURL> orderByComparator)
1187                    throws NoSuchLayoutFriendlyURLException {
1188                    LayoutFriendlyURL layoutFriendlyURL = fetchByUuid_C_Last(uuid,
1189                                    companyId, orderByComparator);
1190    
1191                    if (layoutFriendlyURL != null) {
1192                            return layoutFriendlyURL;
1193                    }
1194    
1195                    StringBundler msg = new StringBundler(6);
1196    
1197                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1198    
1199                    msg.append("uuid=");
1200                    msg.append(uuid);
1201    
1202                    msg.append(", companyId=");
1203                    msg.append(companyId);
1204    
1205                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1206    
1207                    throw new NoSuchLayoutFriendlyURLException(msg.toString());
1208            }
1209    
1210            /**
1211             * Returns the last layout friendly u r l in the ordered set where uuid = &#63; and companyId = &#63;.
1212             *
1213             * @param uuid the uuid
1214             * @param companyId the company ID
1215             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1216             * @return the last matching layout friendly u r l, or <code>null</code> if a matching layout friendly u r l could not be found
1217             */
1218            @Override
1219            public LayoutFriendlyURL fetchByUuid_C_Last(String uuid, long companyId,
1220                    OrderByComparator<LayoutFriendlyURL> orderByComparator) {
1221                    int count = countByUuid_C(uuid, companyId);
1222    
1223                    if (count == 0) {
1224                            return null;
1225                    }
1226    
1227                    List<LayoutFriendlyURL> list = findByUuid_C(uuid, companyId, count - 1,
1228                                    count, orderByComparator);
1229    
1230                    if (!list.isEmpty()) {
1231                            return list.get(0);
1232                    }
1233    
1234                    return null;
1235            }
1236    
1237            /**
1238             * Returns the layout friendly u r ls before and after the current layout friendly u r l in the ordered set where uuid = &#63; and companyId = &#63;.
1239             *
1240             * @param layoutFriendlyURLId the primary key of the current layout friendly u r l
1241             * @param uuid the uuid
1242             * @param companyId the company ID
1243             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1244             * @return the previous, current, and next layout friendly u r l
1245             * @throws NoSuchLayoutFriendlyURLException if a layout friendly u r l with the primary key could not be found
1246             */
1247            @Override
1248            public LayoutFriendlyURL[] findByUuid_C_PrevAndNext(
1249                    long layoutFriendlyURLId, String uuid, long companyId,
1250                    OrderByComparator<LayoutFriendlyURL> orderByComparator)
1251                    throws NoSuchLayoutFriendlyURLException {
1252                    LayoutFriendlyURL layoutFriendlyURL = findByPrimaryKey(layoutFriendlyURLId);
1253    
1254                    Session session = null;
1255    
1256                    try {
1257                            session = openSession();
1258    
1259                            LayoutFriendlyURL[] array = new LayoutFriendlyURLImpl[3];
1260    
1261                            array[0] = getByUuid_C_PrevAndNext(session, layoutFriendlyURL,
1262                                            uuid, companyId, orderByComparator, true);
1263    
1264                            array[1] = layoutFriendlyURL;
1265    
1266                            array[2] = getByUuid_C_PrevAndNext(session, layoutFriendlyURL,
1267                                            uuid, companyId, orderByComparator, false);
1268    
1269                            return array;
1270                    }
1271                    catch (Exception e) {
1272                            throw processException(e);
1273                    }
1274                    finally {
1275                            closeSession(session);
1276                    }
1277            }
1278    
1279            protected LayoutFriendlyURL getByUuid_C_PrevAndNext(Session session,
1280                    LayoutFriendlyURL layoutFriendlyURL, String uuid, long companyId,
1281                    OrderByComparator<LayoutFriendlyURL> orderByComparator, boolean previous) {
1282                    StringBundler query = null;
1283    
1284                    if (orderByComparator != null) {
1285                            query = new StringBundler(5 +
1286                                            (orderByComparator.getOrderByConditionFields().length * 3) +
1287                                            (orderByComparator.getOrderByFields().length * 3));
1288                    }
1289                    else {
1290                            query = new StringBundler(4);
1291                    }
1292    
1293                    query.append(_SQL_SELECT_LAYOUTFRIENDLYURL_WHERE);
1294    
1295                    boolean bindUuid = false;
1296    
1297                    if (uuid == null) {
1298                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1299                    }
1300                    else if (uuid.equals(StringPool.BLANK)) {
1301                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1302                    }
1303                    else {
1304                            bindUuid = true;
1305    
1306                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1307                    }
1308    
1309                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1310    
1311                    if (orderByComparator != null) {
1312                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1313    
1314                            if (orderByConditionFields.length > 0) {
1315                                    query.append(WHERE_AND);
1316                            }
1317    
1318                            for (int i = 0; i < orderByConditionFields.length; i++) {
1319                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1320                                    query.append(orderByConditionFields[i]);
1321    
1322                                    if ((i + 1) < orderByConditionFields.length) {
1323                                            if (orderByComparator.isAscending() ^ previous) {
1324                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1325                                            }
1326                                            else {
1327                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1328                                            }
1329                                    }
1330                                    else {
1331                                            if (orderByComparator.isAscending() ^ previous) {
1332                                                    query.append(WHERE_GREATER_THAN);
1333                                            }
1334                                            else {
1335                                                    query.append(WHERE_LESSER_THAN);
1336                                            }
1337                                    }
1338                            }
1339    
1340                            query.append(ORDER_BY_CLAUSE);
1341    
1342                            String[] orderByFields = orderByComparator.getOrderByFields();
1343    
1344                            for (int i = 0; i < orderByFields.length; i++) {
1345                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1346                                    query.append(orderByFields[i]);
1347    
1348                                    if ((i + 1) < orderByFields.length) {
1349                                            if (orderByComparator.isAscending() ^ previous) {
1350                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1351                                            }
1352                                            else {
1353                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1354                                            }
1355                                    }
1356                                    else {
1357                                            if (orderByComparator.isAscending() ^ previous) {
1358                                                    query.append(ORDER_BY_ASC);
1359                                            }
1360                                            else {
1361                                                    query.append(ORDER_BY_DESC);
1362                                            }
1363                                    }
1364                            }
1365                    }
1366                    else {
1367                            query.append(LayoutFriendlyURLModelImpl.ORDER_BY_JPQL);
1368                    }
1369    
1370                    String sql = query.toString();
1371    
1372                    Query q = session.createQuery(sql);
1373    
1374                    q.setFirstResult(0);
1375                    q.setMaxResults(2);
1376    
1377                    QueryPos qPos = QueryPos.getInstance(q);
1378    
1379                    if (bindUuid) {
1380                            qPos.add(uuid);
1381                    }
1382    
1383                    qPos.add(companyId);
1384    
1385                    if (orderByComparator != null) {
1386                            Object[] values = orderByComparator.getOrderByConditionValues(layoutFriendlyURL);
1387    
1388                            for (Object value : values) {
1389                                    qPos.add(value);
1390                            }
1391                    }
1392    
1393                    List<LayoutFriendlyURL> list = q.list();
1394    
1395                    if (list.size() == 2) {
1396                            return list.get(1);
1397                    }
1398                    else {
1399                            return null;
1400                    }
1401            }
1402    
1403            /**
1404             * Removes all the layout friendly u r ls where uuid = &#63; and companyId = &#63; from the database.
1405             *
1406             * @param uuid the uuid
1407             * @param companyId the company ID
1408             */
1409            @Override
1410            public void removeByUuid_C(String uuid, long companyId) {
1411                    for (LayoutFriendlyURL layoutFriendlyURL : findByUuid_C(uuid,
1412                                    companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1413                            remove(layoutFriendlyURL);
1414                    }
1415            }
1416    
1417            /**
1418             * Returns the number of layout friendly u r ls where uuid = &#63; and companyId = &#63;.
1419             *
1420             * @param uuid the uuid
1421             * @param companyId the company ID
1422             * @return the number of matching layout friendly u r ls
1423             */
1424            @Override
1425            public int countByUuid_C(String uuid, long companyId) {
1426                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1427    
1428                    Object[] finderArgs = new Object[] { uuid, companyId };
1429    
1430                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1431    
1432                    if (count == null) {
1433                            StringBundler query = new StringBundler(3);
1434    
1435                            query.append(_SQL_COUNT_LAYOUTFRIENDLYURL_WHERE);
1436    
1437                            boolean bindUuid = false;
1438    
1439                            if (uuid == null) {
1440                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1441                            }
1442                            else if (uuid.equals(StringPool.BLANK)) {
1443                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1444                            }
1445                            else {
1446                                    bindUuid = true;
1447    
1448                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1449                            }
1450    
1451                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1452    
1453                            String sql = query.toString();
1454    
1455                            Session session = null;
1456    
1457                            try {
1458                                    session = openSession();
1459    
1460                                    Query q = session.createQuery(sql);
1461    
1462                                    QueryPos qPos = QueryPos.getInstance(q);
1463    
1464                                    if (bindUuid) {
1465                                            qPos.add(uuid);
1466                                    }
1467    
1468                                    qPos.add(companyId);
1469    
1470                                    count = (Long)q.uniqueResult();
1471    
1472                                    finderCache.putResult(finderPath, finderArgs, count);
1473                            }
1474                            catch (Exception e) {
1475                                    finderCache.removeResult(finderPath, finderArgs);
1476    
1477                                    throw processException(e);
1478                            }
1479                            finally {
1480                                    closeSession(session);
1481                            }
1482                    }
1483    
1484                    return count.intValue();
1485            }
1486    
1487            private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "layoutFriendlyURL.uuid IS NULL AND ";
1488            private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "layoutFriendlyURL.uuid = ? AND ";
1489            private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(layoutFriendlyURL.uuid IS NULL OR layoutFriendlyURL.uuid = '') AND ";
1490            private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "layoutFriendlyURL.companyId = ?";
1491            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(LayoutFriendlyURLModelImpl.ENTITY_CACHE_ENABLED,
1492                            LayoutFriendlyURLModelImpl.FINDER_CACHE_ENABLED,
1493                            LayoutFriendlyURLImpl.class,
1494                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
1495                            new String[] {
1496                                    Long.class.getName(),
1497                                    
1498                            Integer.class.getName(), Integer.class.getName(),
1499                                    OrderByComparator.class.getName()
1500                            });
1501            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
1502                    new FinderPath(LayoutFriendlyURLModelImpl.ENTITY_CACHE_ENABLED,
1503                            LayoutFriendlyURLModelImpl.FINDER_CACHE_ENABLED,
1504                            LayoutFriendlyURLImpl.class,
1505                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
1506                            new String[] { Long.class.getName() },
1507                            LayoutFriendlyURLModelImpl.GROUPID_COLUMN_BITMASK);
1508            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(LayoutFriendlyURLModelImpl.ENTITY_CACHE_ENABLED,
1509                            LayoutFriendlyURLModelImpl.FINDER_CACHE_ENABLED, Long.class,
1510                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
1511                            new String[] { Long.class.getName() });
1512    
1513            /**
1514             * Returns all the layout friendly u r ls where groupId = &#63;.
1515             *
1516             * @param groupId the group ID
1517             * @return the matching layout friendly u r ls
1518             */
1519            @Override
1520            public List<LayoutFriendlyURL> findByGroupId(long groupId) {
1521                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1522            }
1523    
1524            /**
1525             * Returns a range of all the layout friendly u r ls where groupId = &#63;.
1526             *
1527             * <p>
1528             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link LayoutFriendlyURLModelImpl}. 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.
1529             * </p>
1530             *
1531             * @param groupId the group ID
1532             * @param start the lower bound of the range of layout friendly u r ls
1533             * @param end the upper bound of the range of layout friendly u r ls (not inclusive)
1534             * @return the range of matching layout friendly u r ls
1535             */
1536            @Override
1537            public List<LayoutFriendlyURL> findByGroupId(long groupId, int start,
1538                    int end) {
1539                    return findByGroupId(groupId, start, end, null);
1540            }
1541    
1542            /**
1543             * Returns an ordered range of all the layout friendly u r ls where groupId = &#63;.
1544             *
1545             * <p>
1546             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link LayoutFriendlyURLModelImpl}. 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.
1547             * </p>
1548             *
1549             * @param groupId the group ID
1550             * @param start the lower bound of the range of layout friendly u r ls
1551             * @param end the upper bound of the range of layout friendly u r ls (not inclusive)
1552             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1553             * @return the ordered range of matching layout friendly u r ls
1554             */
1555            @Override
1556            public List<LayoutFriendlyURL> findByGroupId(long groupId, int start,
1557                    int end, OrderByComparator<LayoutFriendlyURL> orderByComparator) {
1558                    return findByGroupId(groupId, start, end, orderByComparator, true);
1559            }
1560    
1561            /**
1562             * Returns an ordered range of all the layout friendly u r ls where groupId = &#63;.
1563             *
1564             * <p>
1565             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link LayoutFriendlyURLModelImpl}. 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.
1566             * </p>
1567             *
1568             * @param groupId the group ID
1569             * @param start the lower bound of the range of layout friendly u r ls
1570             * @param end the upper bound of the range of layout friendly u r ls (not inclusive)
1571             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1572             * @param retrieveFromCache whether to retrieve from the finder cache
1573             * @return the ordered range of matching layout friendly u r ls
1574             */
1575            @Override
1576            public List<LayoutFriendlyURL> findByGroupId(long groupId, int start,
1577                    int end, OrderByComparator<LayoutFriendlyURL> orderByComparator,
1578                    boolean retrieveFromCache) {
1579                    boolean pagination = true;
1580                    FinderPath finderPath = null;
1581                    Object[] finderArgs = null;
1582    
1583                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1584                                    (orderByComparator == null)) {
1585                            pagination = false;
1586                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1587                            finderArgs = new Object[] { groupId };
1588                    }
1589                    else {
1590                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1591                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
1592                    }
1593    
1594                    List<LayoutFriendlyURL> list = null;
1595    
1596                    if (retrieveFromCache) {
1597                            list = (List<LayoutFriendlyURL>)finderCache.getResult(finderPath,
1598                                            finderArgs, this);
1599    
1600                            if ((list != null) && !list.isEmpty()) {
1601                                    for (LayoutFriendlyURL layoutFriendlyURL : list) {
1602                                            if ((groupId != layoutFriendlyURL.getGroupId())) {
1603                                                    list = null;
1604    
1605                                                    break;
1606                                            }
1607                                    }
1608                            }
1609                    }
1610    
1611                    if (list == null) {
1612                            StringBundler query = null;
1613    
1614                            if (orderByComparator != null) {
1615                                    query = new StringBundler(3 +
1616                                                    (orderByComparator.getOrderByFields().length * 2));
1617                            }
1618                            else {
1619                                    query = new StringBundler(3);
1620                            }
1621    
1622                            query.append(_SQL_SELECT_LAYOUTFRIENDLYURL_WHERE);
1623    
1624                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1625    
1626                            if (orderByComparator != null) {
1627                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1628                                            orderByComparator);
1629                            }
1630                            else
1631                             if (pagination) {
1632                                    query.append(LayoutFriendlyURLModelImpl.ORDER_BY_JPQL);
1633                            }
1634    
1635                            String sql = query.toString();
1636    
1637                            Session session = null;
1638    
1639                            try {
1640                                    session = openSession();
1641    
1642                                    Query q = session.createQuery(sql);
1643    
1644                                    QueryPos qPos = QueryPos.getInstance(q);
1645    
1646                                    qPos.add(groupId);
1647    
1648                                    if (!pagination) {
1649                                            list = (List<LayoutFriendlyURL>)QueryUtil.list(q,
1650                                                            getDialect(), start, end, false);
1651    
1652                                            Collections.sort(list);
1653    
1654                                            list = Collections.unmodifiableList(list);
1655                                    }
1656                                    else {
1657                                            list = (List<LayoutFriendlyURL>)QueryUtil.list(q,
1658                                                            getDialect(), start, end);
1659                                    }
1660    
1661                                    cacheResult(list);
1662    
1663                                    finderCache.putResult(finderPath, finderArgs, list);
1664                            }
1665                            catch (Exception e) {
1666                                    finderCache.removeResult(finderPath, finderArgs);
1667    
1668                                    throw processException(e);
1669                            }
1670                            finally {
1671                                    closeSession(session);
1672                            }
1673                    }
1674    
1675                    return list;
1676            }
1677    
1678            /**
1679             * Returns the first layout friendly u r l in the ordered set where groupId = &#63;.
1680             *
1681             * @param groupId the group ID
1682             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1683             * @return the first matching layout friendly u r l
1684             * @throws NoSuchLayoutFriendlyURLException if a matching layout friendly u r l could not be found
1685             */
1686            @Override
1687            public LayoutFriendlyURL findByGroupId_First(long groupId,
1688                    OrderByComparator<LayoutFriendlyURL> orderByComparator)
1689                    throws NoSuchLayoutFriendlyURLException {
1690                    LayoutFriendlyURL layoutFriendlyURL = fetchByGroupId_First(groupId,
1691                                    orderByComparator);
1692    
1693                    if (layoutFriendlyURL != null) {
1694                            return layoutFriendlyURL;
1695                    }
1696    
1697                    StringBundler msg = new StringBundler(4);
1698    
1699                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1700    
1701                    msg.append("groupId=");
1702                    msg.append(groupId);
1703    
1704                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1705    
1706                    throw new NoSuchLayoutFriendlyURLException(msg.toString());
1707            }
1708    
1709            /**
1710             * Returns the first layout friendly u r l in the ordered set where groupId = &#63;.
1711             *
1712             * @param groupId the group ID
1713             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1714             * @return the first matching layout friendly u r l, or <code>null</code> if a matching layout friendly u r l could not be found
1715             */
1716            @Override
1717            public LayoutFriendlyURL fetchByGroupId_First(long groupId,
1718                    OrderByComparator<LayoutFriendlyURL> orderByComparator) {
1719                    List<LayoutFriendlyURL> list = findByGroupId(groupId, 0, 1,
1720                                    orderByComparator);
1721    
1722                    if (!list.isEmpty()) {
1723                            return list.get(0);
1724                    }
1725    
1726                    return null;
1727            }
1728    
1729            /**
1730             * Returns the last layout friendly u r l in the ordered set where groupId = &#63;.
1731             *
1732             * @param groupId the group ID
1733             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1734             * @return the last matching layout friendly u r l
1735             * @throws NoSuchLayoutFriendlyURLException if a matching layout friendly u r l could not be found
1736             */
1737            @Override
1738            public LayoutFriendlyURL findByGroupId_Last(long groupId,
1739                    OrderByComparator<LayoutFriendlyURL> orderByComparator)
1740                    throws NoSuchLayoutFriendlyURLException {
1741                    LayoutFriendlyURL layoutFriendlyURL = fetchByGroupId_Last(groupId,
1742                                    orderByComparator);
1743    
1744                    if (layoutFriendlyURL != null) {
1745                            return layoutFriendlyURL;
1746                    }
1747    
1748                    StringBundler msg = new StringBundler(4);
1749    
1750                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1751    
1752                    msg.append("groupId=");
1753                    msg.append(groupId);
1754    
1755                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1756    
1757                    throw new NoSuchLayoutFriendlyURLException(msg.toString());
1758            }
1759    
1760            /**
1761             * Returns the last layout friendly u r l in the ordered set where groupId = &#63;.
1762             *
1763             * @param groupId the group ID
1764             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1765             * @return the last matching layout friendly u r l, or <code>null</code> if a matching layout friendly u r l could not be found
1766             */
1767            @Override
1768            public LayoutFriendlyURL fetchByGroupId_Last(long groupId,
1769                    OrderByComparator<LayoutFriendlyURL> orderByComparator) {
1770                    int count = countByGroupId(groupId);
1771    
1772                    if (count == 0) {
1773                            return null;
1774                    }
1775    
1776                    List<LayoutFriendlyURL> list = findByGroupId(groupId, count - 1, count,
1777                                    orderByComparator);
1778    
1779                    if (!list.isEmpty()) {
1780                            return list.get(0);
1781                    }
1782    
1783                    return null;
1784            }
1785    
1786            /**
1787             * Returns the layout friendly u r ls before and after the current layout friendly u r l in the ordered set where groupId = &#63;.
1788             *
1789             * @param layoutFriendlyURLId the primary key of the current layout friendly u r l
1790             * @param groupId the group ID
1791             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1792             * @return the previous, current, and next layout friendly u r l
1793             * @throws NoSuchLayoutFriendlyURLException if a layout friendly u r l with the primary key could not be found
1794             */
1795            @Override
1796            public LayoutFriendlyURL[] findByGroupId_PrevAndNext(
1797                    long layoutFriendlyURLId, long groupId,
1798                    OrderByComparator<LayoutFriendlyURL> orderByComparator)
1799                    throws NoSuchLayoutFriendlyURLException {
1800                    LayoutFriendlyURL layoutFriendlyURL = findByPrimaryKey(layoutFriendlyURLId);
1801    
1802                    Session session = null;
1803    
1804                    try {
1805                            session = openSession();
1806    
1807                            LayoutFriendlyURL[] array = new LayoutFriendlyURLImpl[3];
1808    
1809                            array[0] = getByGroupId_PrevAndNext(session, layoutFriendlyURL,
1810                                            groupId, orderByComparator, true);
1811    
1812                            array[1] = layoutFriendlyURL;
1813    
1814                            array[2] = getByGroupId_PrevAndNext(session, layoutFriendlyURL,
1815                                            groupId, orderByComparator, false);
1816    
1817                            return array;
1818                    }
1819                    catch (Exception e) {
1820                            throw processException(e);
1821                    }
1822                    finally {
1823                            closeSession(session);
1824                    }
1825            }
1826    
1827            protected LayoutFriendlyURL getByGroupId_PrevAndNext(Session session,
1828                    LayoutFriendlyURL layoutFriendlyURL, long groupId,
1829                    OrderByComparator<LayoutFriendlyURL> orderByComparator, boolean previous) {
1830                    StringBundler query = null;
1831    
1832                    if (orderByComparator != null) {
1833                            query = new StringBundler(4 +
1834                                            (orderByComparator.getOrderByConditionFields().length * 3) +
1835                                            (orderByComparator.getOrderByFields().length * 3));
1836                    }
1837                    else {
1838                            query = new StringBundler(3);
1839                    }
1840    
1841                    query.append(_SQL_SELECT_LAYOUTFRIENDLYURL_WHERE);
1842    
1843                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1844    
1845                    if (orderByComparator != null) {
1846                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1847    
1848                            if (orderByConditionFields.length > 0) {
1849                                    query.append(WHERE_AND);
1850                            }
1851    
1852                            for (int i = 0; i < orderByConditionFields.length; i++) {
1853                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1854                                    query.append(orderByConditionFields[i]);
1855    
1856                                    if ((i + 1) < orderByConditionFields.length) {
1857                                            if (orderByComparator.isAscending() ^ previous) {
1858                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1859                                            }
1860                                            else {
1861                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1862                                            }
1863                                    }
1864                                    else {
1865                                            if (orderByComparator.isAscending() ^ previous) {
1866                                                    query.append(WHERE_GREATER_THAN);
1867                                            }
1868                                            else {
1869                                                    query.append(WHERE_LESSER_THAN);
1870                                            }
1871                                    }
1872                            }
1873    
1874                            query.append(ORDER_BY_CLAUSE);
1875    
1876                            String[] orderByFields = orderByComparator.getOrderByFields();
1877    
1878                            for (int i = 0; i < orderByFields.length; i++) {
1879                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1880                                    query.append(orderByFields[i]);
1881    
1882                                    if ((i + 1) < orderByFields.length) {
1883                                            if (orderByComparator.isAscending() ^ previous) {
1884                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1885                                            }
1886                                            else {
1887                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1888                                            }
1889                                    }
1890                                    else {
1891                                            if (orderByComparator.isAscending() ^ previous) {
1892                                                    query.append(ORDER_BY_ASC);
1893                                            }
1894                                            else {
1895                                                    query.append(ORDER_BY_DESC);
1896                                            }
1897                                    }
1898                            }
1899                    }
1900                    else {
1901                            query.append(LayoutFriendlyURLModelImpl.ORDER_BY_JPQL);
1902                    }
1903    
1904                    String sql = query.toString();
1905    
1906                    Query q = session.createQuery(sql);
1907    
1908                    q.setFirstResult(0);
1909                    q.setMaxResults(2);
1910    
1911                    QueryPos qPos = QueryPos.getInstance(q);
1912    
1913                    qPos.add(groupId);
1914    
1915                    if (orderByComparator != null) {
1916                            Object[] values = orderByComparator.getOrderByConditionValues(layoutFriendlyURL);
1917    
1918                            for (Object value : values) {
1919                                    qPos.add(value);
1920                            }
1921                    }
1922    
1923                    List<LayoutFriendlyURL> list = q.list();
1924    
1925                    if (list.size() == 2) {
1926                            return list.get(1);
1927                    }
1928                    else {
1929                            return null;
1930                    }
1931            }
1932    
1933            /**
1934             * Removes all the layout friendly u r ls where groupId = &#63; from the database.
1935             *
1936             * @param groupId the group ID
1937             */
1938            @Override
1939            public void removeByGroupId(long groupId) {
1940                    for (LayoutFriendlyURL layoutFriendlyURL : findByGroupId(groupId,
1941                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1942                            remove(layoutFriendlyURL);
1943                    }
1944            }
1945    
1946            /**
1947             * Returns the number of layout friendly u r ls where groupId = &#63;.
1948             *
1949             * @param groupId the group ID
1950             * @return the number of matching layout friendly u r ls
1951             */
1952            @Override
1953            public int countByGroupId(long groupId) {
1954                    FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
1955    
1956                    Object[] finderArgs = new Object[] { groupId };
1957    
1958                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1959    
1960                    if (count == null) {
1961                            StringBundler query = new StringBundler(2);
1962    
1963                            query.append(_SQL_COUNT_LAYOUTFRIENDLYURL_WHERE);
1964    
1965                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1966    
1967                            String sql = query.toString();
1968    
1969                            Session session = null;
1970    
1971                            try {
1972                                    session = openSession();
1973    
1974                                    Query q = session.createQuery(sql);
1975    
1976                                    QueryPos qPos = QueryPos.getInstance(q);
1977    
1978                                    qPos.add(groupId);
1979    
1980                                    count = (Long)q.uniqueResult();
1981    
1982                                    finderCache.putResult(finderPath, finderArgs, count);
1983                            }
1984                            catch (Exception e) {
1985                                    finderCache.removeResult(finderPath, finderArgs);
1986    
1987                                    throw processException(e);
1988                            }
1989                            finally {
1990                                    closeSession(session);
1991                            }
1992                    }
1993    
1994                    return count.intValue();
1995            }
1996    
1997            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "layoutFriendlyURL.groupId = ?";
1998            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
1999                    new FinderPath(LayoutFriendlyURLModelImpl.ENTITY_CACHE_ENABLED,
2000                            LayoutFriendlyURLModelImpl.FINDER_CACHE_ENABLED,
2001                            LayoutFriendlyURLImpl.class,
2002                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
2003                            new String[] {
2004                                    Long.class.getName(),
2005                                    
2006                            Integer.class.getName(), Integer.class.getName(),
2007                                    OrderByComparator.class.getName()
2008                            });
2009            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
2010                    new FinderPath(LayoutFriendlyURLModelImpl.ENTITY_CACHE_ENABLED,
2011                            LayoutFriendlyURLModelImpl.FINDER_CACHE_ENABLED,
2012                            LayoutFriendlyURLImpl.class,
2013                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
2014                            new String[] { Long.class.getName() },
2015                            LayoutFriendlyURLModelImpl.COMPANYID_COLUMN_BITMASK);
2016            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(LayoutFriendlyURLModelImpl.ENTITY_CACHE_ENABLED,
2017                            LayoutFriendlyURLModelImpl.FINDER_CACHE_ENABLED, Long.class,
2018                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
2019                            new String[] { Long.class.getName() });
2020    
2021            /**
2022             * Returns all the layout friendly u r ls where companyId = &#63;.
2023             *
2024             * @param companyId the company ID
2025             * @return the matching layout friendly u r ls
2026             */
2027            @Override
2028            public List<LayoutFriendlyURL> findByCompanyId(long companyId) {
2029                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2030                            null);
2031            }
2032    
2033            /**
2034             * Returns a range of all the layout friendly u r ls where companyId = &#63;.
2035             *
2036             * <p>
2037             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link LayoutFriendlyURLModelImpl}. 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.
2038             * </p>
2039             *
2040             * @param companyId the company ID
2041             * @param start the lower bound of the range of layout friendly u r ls
2042             * @param end the upper bound of the range of layout friendly u r ls (not inclusive)
2043             * @return the range of matching layout friendly u r ls
2044             */
2045            @Override
2046            public List<LayoutFriendlyURL> findByCompanyId(long companyId, int start,
2047                    int end) {
2048                    return findByCompanyId(companyId, start, end, null);
2049            }
2050    
2051            /**
2052             * Returns an ordered range of all the layout friendly u r ls where companyId = &#63;.
2053             *
2054             * <p>
2055             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link LayoutFriendlyURLModelImpl}. 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.
2056             * </p>
2057             *
2058             * @param companyId the company ID
2059             * @param start the lower bound of the range of layout friendly u r ls
2060             * @param end the upper bound of the range of layout friendly u r ls (not inclusive)
2061             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2062             * @return the ordered range of matching layout friendly u r ls
2063             */
2064            @Override
2065            public List<LayoutFriendlyURL> findByCompanyId(long companyId, int start,
2066                    int end, OrderByComparator<LayoutFriendlyURL> orderByComparator) {
2067                    return findByCompanyId(companyId, start, end, orderByComparator, true);
2068            }
2069    
2070            /**
2071             * Returns an ordered range of all the layout friendly u r ls where companyId = &#63;.
2072             *
2073             * <p>
2074             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link LayoutFriendlyURLModelImpl}. 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.
2075             * </p>
2076             *
2077             * @param companyId the company ID
2078             * @param start the lower bound of the range of layout friendly u r ls
2079             * @param end the upper bound of the range of layout friendly u r ls (not inclusive)
2080             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2081             * @param retrieveFromCache whether to retrieve from the finder cache
2082             * @return the ordered range of matching layout friendly u r ls
2083             */
2084            @Override
2085            public List<LayoutFriendlyURL> findByCompanyId(long companyId, int start,
2086                    int end, OrderByComparator<LayoutFriendlyURL> orderByComparator,
2087                    boolean retrieveFromCache) {
2088                    boolean pagination = true;
2089                    FinderPath finderPath = null;
2090                    Object[] finderArgs = null;
2091    
2092                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2093                                    (orderByComparator == null)) {
2094                            pagination = false;
2095                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
2096                            finderArgs = new Object[] { companyId };
2097                    }
2098                    else {
2099                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
2100                            finderArgs = new Object[] { companyId, start, end, orderByComparator };
2101                    }
2102    
2103                    List<LayoutFriendlyURL> list = null;
2104    
2105                    if (retrieveFromCache) {
2106                            list = (List<LayoutFriendlyURL>)finderCache.getResult(finderPath,
2107                                            finderArgs, this);
2108    
2109                            if ((list != null) && !list.isEmpty()) {
2110                                    for (LayoutFriendlyURL layoutFriendlyURL : list) {
2111                                            if ((companyId != layoutFriendlyURL.getCompanyId())) {
2112                                                    list = null;
2113    
2114                                                    break;
2115                                            }
2116                                    }
2117                            }
2118                    }
2119    
2120                    if (list == null) {
2121                            StringBundler query = null;
2122    
2123                            if (orderByComparator != null) {
2124                                    query = new StringBundler(3 +
2125                                                    (orderByComparator.getOrderByFields().length * 2));
2126                            }
2127                            else {
2128                                    query = new StringBundler(3);
2129                            }
2130    
2131                            query.append(_SQL_SELECT_LAYOUTFRIENDLYURL_WHERE);
2132    
2133                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2134    
2135                            if (orderByComparator != null) {
2136                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2137                                            orderByComparator);
2138                            }
2139                            else
2140                             if (pagination) {
2141                                    query.append(LayoutFriendlyURLModelImpl.ORDER_BY_JPQL);
2142                            }
2143    
2144                            String sql = query.toString();
2145    
2146                            Session session = null;
2147    
2148                            try {
2149                                    session = openSession();
2150    
2151                                    Query q = session.createQuery(sql);
2152    
2153                                    QueryPos qPos = QueryPos.getInstance(q);
2154    
2155                                    qPos.add(companyId);
2156    
2157                                    if (!pagination) {
2158                                            list = (List<LayoutFriendlyURL>)QueryUtil.list(q,
2159                                                            getDialect(), start, end, false);
2160    
2161                                            Collections.sort(list);
2162    
2163                                            list = Collections.unmodifiableList(list);
2164                                    }
2165                                    else {
2166                                            list = (List<LayoutFriendlyURL>)QueryUtil.list(q,
2167                                                            getDialect(), start, end);
2168                                    }
2169    
2170                                    cacheResult(list);
2171    
2172                                    finderCache.putResult(finderPath, finderArgs, list);
2173                            }
2174                            catch (Exception e) {
2175                                    finderCache.removeResult(finderPath, finderArgs);
2176    
2177                                    throw processException(e);
2178                            }
2179                            finally {
2180                                    closeSession(session);
2181                            }
2182                    }
2183    
2184                    return list;
2185            }
2186    
2187            /**
2188             * Returns the first layout friendly u r l in the ordered set where companyId = &#63;.
2189             *
2190             * @param companyId the company ID
2191             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2192             * @return the first matching layout friendly u r l
2193             * @throws NoSuchLayoutFriendlyURLException if a matching layout friendly u r l could not be found
2194             */
2195            @Override
2196            public LayoutFriendlyURL findByCompanyId_First(long companyId,
2197                    OrderByComparator<LayoutFriendlyURL> orderByComparator)
2198                    throws NoSuchLayoutFriendlyURLException {
2199                    LayoutFriendlyURL layoutFriendlyURL = fetchByCompanyId_First(companyId,
2200                                    orderByComparator);
2201    
2202                    if (layoutFriendlyURL != null) {
2203                            return layoutFriendlyURL;
2204                    }
2205    
2206                    StringBundler msg = new StringBundler(4);
2207    
2208                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2209    
2210                    msg.append("companyId=");
2211                    msg.append(companyId);
2212    
2213                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2214    
2215                    throw new NoSuchLayoutFriendlyURLException(msg.toString());
2216            }
2217    
2218            /**
2219             * Returns the first layout friendly u r l in the ordered set where companyId = &#63;.
2220             *
2221             * @param companyId the company ID
2222             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2223             * @return the first matching layout friendly u r l, or <code>null</code> if a matching layout friendly u r l could not be found
2224             */
2225            @Override
2226            public LayoutFriendlyURL fetchByCompanyId_First(long companyId,
2227                    OrderByComparator<LayoutFriendlyURL> orderByComparator) {
2228                    List<LayoutFriendlyURL> list = findByCompanyId(companyId, 0, 1,
2229                                    orderByComparator);
2230    
2231                    if (!list.isEmpty()) {
2232                            return list.get(0);
2233                    }
2234    
2235                    return null;
2236            }
2237    
2238            /**
2239             * Returns the last layout friendly u r l in the ordered set where companyId = &#63;.
2240             *
2241             * @param companyId the company ID
2242             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2243             * @return the last matching layout friendly u r l
2244             * @throws NoSuchLayoutFriendlyURLException if a matching layout friendly u r l could not be found
2245             */
2246            @Override
2247            public LayoutFriendlyURL findByCompanyId_Last(long companyId,
2248                    OrderByComparator<LayoutFriendlyURL> orderByComparator)
2249                    throws NoSuchLayoutFriendlyURLException {
2250                    LayoutFriendlyURL layoutFriendlyURL = fetchByCompanyId_Last(companyId,
2251                                    orderByComparator);
2252    
2253                    if (layoutFriendlyURL != null) {
2254                            return layoutFriendlyURL;
2255                    }
2256    
2257                    StringBundler msg = new StringBundler(4);
2258    
2259                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2260    
2261                    msg.append("companyId=");
2262                    msg.append(companyId);
2263    
2264                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2265    
2266                    throw new NoSuchLayoutFriendlyURLException(msg.toString());
2267            }
2268    
2269            /**
2270             * Returns the last layout friendly u r l in the ordered set where companyId = &#63;.
2271             *
2272             * @param companyId the company ID
2273             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2274             * @return the last matching layout friendly u r l, or <code>null</code> if a matching layout friendly u r l could not be found
2275             */
2276            @Override
2277            public LayoutFriendlyURL fetchByCompanyId_Last(long companyId,
2278                    OrderByComparator<LayoutFriendlyURL> orderByComparator) {
2279                    int count = countByCompanyId(companyId);
2280    
2281                    if (count == 0) {
2282                            return null;
2283                    }
2284    
2285                    List<LayoutFriendlyURL> list = findByCompanyId(companyId, count - 1,
2286                                    count, orderByComparator);
2287    
2288                    if (!list.isEmpty()) {
2289                            return list.get(0);
2290                    }
2291    
2292                    return null;
2293            }
2294    
2295            /**
2296             * Returns the layout friendly u r ls before and after the current layout friendly u r l in the ordered set where companyId = &#63;.
2297             *
2298             * @param layoutFriendlyURLId the primary key of the current layout friendly u r l
2299             * @param companyId the company ID
2300             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2301             * @return the previous, current, and next layout friendly u r l
2302             * @throws NoSuchLayoutFriendlyURLException if a layout friendly u r l with the primary key could not be found
2303             */
2304            @Override
2305            public LayoutFriendlyURL[] findByCompanyId_PrevAndNext(
2306                    long layoutFriendlyURLId, long companyId,
2307                    OrderByComparator<LayoutFriendlyURL> orderByComparator)
2308                    throws NoSuchLayoutFriendlyURLException {
2309                    LayoutFriendlyURL layoutFriendlyURL = findByPrimaryKey(layoutFriendlyURLId);
2310    
2311                    Session session = null;
2312    
2313                    try {
2314                            session = openSession();
2315    
2316                            LayoutFriendlyURL[] array = new LayoutFriendlyURLImpl[3];
2317    
2318                            array[0] = getByCompanyId_PrevAndNext(session, layoutFriendlyURL,
2319                                            companyId, orderByComparator, true);
2320    
2321                            array[1] = layoutFriendlyURL;
2322    
2323                            array[2] = getByCompanyId_PrevAndNext(session, layoutFriendlyURL,
2324                                            companyId, orderByComparator, false);
2325    
2326                            return array;
2327                    }
2328                    catch (Exception e) {
2329                            throw processException(e);
2330                    }
2331                    finally {
2332                            closeSession(session);
2333                    }
2334            }
2335    
2336            protected LayoutFriendlyURL getByCompanyId_PrevAndNext(Session session,
2337                    LayoutFriendlyURL layoutFriendlyURL, long companyId,
2338                    OrderByComparator<LayoutFriendlyURL> orderByComparator, boolean previous) {
2339                    StringBundler query = null;
2340    
2341                    if (orderByComparator != null) {
2342                            query = new StringBundler(4 +
2343                                            (orderByComparator.getOrderByConditionFields().length * 3) +
2344                                            (orderByComparator.getOrderByFields().length * 3));
2345                    }
2346                    else {
2347                            query = new StringBundler(3);
2348                    }
2349    
2350                    query.append(_SQL_SELECT_LAYOUTFRIENDLYURL_WHERE);
2351    
2352                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2353    
2354                    if (orderByComparator != null) {
2355                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2356    
2357                            if (orderByConditionFields.length > 0) {
2358                                    query.append(WHERE_AND);
2359                            }
2360    
2361                            for (int i = 0; i < orderByConditionFields.length; i++) {
2362                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2363                                    query.append(orderByConditionFields[i]);
2364    
2365                                    if ((i + 1) < orderByConditionFields.length) {
2366                                            if (orderByComparator.isAscending() ^ previous) {
2367                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2368                                            }
2369                                            else {
2370                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2371                                            }
2372                                    }
2373                                    else {
2374                                            if (orderByComparator.isAscending() ^ previous) {
2375                                                    query.append(WHERE_GREATER_THAN);
2376                                            }
2377                                            else {
2378                                                    query.append(WHERE_LESSER_THAN);
2379                                            }
2380                                    }
2381                            }
2382    
2383                            query.append(ORDER_BY_CLAUSE);
2384    
2385                            String[] orderByFields = orderByComparator.getOrderByFields();
2386    
2387                            for (int i = 0; i < orderByFields.length; i++) {
2388                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2389                                    query.append(orderByFields[i]);
2390    
2391                                    if ((i + 1) < orderByFields.length) {
2392                                            if (orderByComparator.isAscending() ^ previous) {
2393                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2394                                            }
2395                                            else {
2396                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2397                                            }
2398                                    }
2399                                    else {
2400                                            if (orderByComparator.isAscending() ^ previous) {
2401                                                    query.append(ORDER_BY_ASC);
2402                                            }
2403                                            else {
2404                                                    query.append(ORDER_BY_DESC);
2405                                            }
2406                                    }
2407                            }
2408                    }
2409                    else {
2410                            query.append(LayoutFriendlyURLModelImpl.ORDER_BY_JPQL);
2411                    }
2412    
2413                    String sql = query.toString();
2414    
2415                    Query q = session.createQuery(sql);
2416    
2417                    q.setFirstResult(0);
2418                    q.setMaxResults(2);
2419    
2420                    QueryPos qPos = QueryPos.getInstance(q);
2421    
2422                    qPos.add(companyId);
2423    
2424                    if (orderByComparator != null) {
2425                            Object[] values = orderByComparator.getOrderByConditionValues(layoutFriendlyURL);
2426    
2427                            for (Object value : values) {
2428                                    qPos.add(value);
2429                            }
2430                    }
2431    
2432                    List<LayoutFriendlyURL> list = q.list();
2433    
2434                    if (list.size() == 2) {
2435                            return list.get(1);
2436                    }
2437                    else {
2438                            return null;
2439                    }
2440            }
2441    
2442            /**
2443             * Removes all the layout friendly u r ls where companyId = &#63; from the database.
2444             *
2445             * @param companyId the company ID
2446             */
2447            @Override
2448            public void removeByCompanyId(long companyId) {
2449                    for (LayoutFriendlyURL layoutFriendlyURL : findByCompanyId(companyId,
2450                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2451                            remove(layoutFriendlyURL);
2452                    }
2453            }
2454    
2455            /**
2456             * Returns the number of layout friendly u r ls where companyId = &#63;.
2457             *
2458             * @param companyId the company ID
2459             * @return the number of matching layout friendly u r ls
2460             */
2461            @Override
2462            public int countByCompanyId(long companyId) {
2463                    FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
2464    
2465                    Object[] finderArgs = new Object[] { companyId };
2466    
2467                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
2468    
2469                    if (count == null) {
2470                            StringBundler query = new StringBundler(2);
2471    
2472                            query.append(_SQL_COUNT_LAYOUTFRIENDLYURL_WHERE);
2473    
2474                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2475    
2476                            String sql = query.toString();
2477    
2478                            Session session = null;
2479    
2480                            try {
2481                                    session = openSession();
2482    
2483                                    Query q = session.createQuery(sql);
2484    
2485                                    QueryPos qPos = QueryPos.getInstance(q);
2486    
2487                                    qPos.add(companyId);
2488    
2489                                    count = (Long)q.uniqueResult();
2490    
2491                                    finderCache.putResult(finderPath, finderArgs, count);
2492                            }
2493                            catch (Exception e) {
2494                                    finderCache.removeResult(finderPath, finderArgs);
2495    
2496                                    throw processException(e);
2497                            }
2498                            finally {
2499                                    closeSession(session);
2500                            }
2501                    }
2502    
2503                    return count.intValue();
2504            }
2505    
2506            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "layoutFriendlyURL.companyId = ?";
2507            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_PLID = new FinderPath(LayoutFriendlyURLModelImpl.ENTITY_CACHE_ENABLED,
2508                            LayoutFriendlyURLModelImpl.FINDER_CACHE_ENABLED,
2509                            LayoutFriendlyURLImpl.class,
2510                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByPlid",
2511                            new String[] {
2512                                    Long.class.getName(),
2513                                    
2514                            Integer.class.getName(), Integer.class.getName(),
2515                                    OrderByComparator.class.getName()
2516                            });
2517            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PLID = new FinderPath(LayoutFriendlyURLModelImpl.ENTITY_CACHE_ENABLED,
2518                            LayoutFriendlyURLModelImpl.FINDER_CACHE_ENABLED,
2519                            LayoutFriendlyURLImpl.class,
2520                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByPlid",
2521                            new String[] { Long.class.getName() },
2522                            LayoutFriendlyURLModelImpl.PLID_COLUMN_BITMASK);
2523            public static final FinderPath FINDER_PATH_COUNT_BY_PLID = new FinderPath(LayoutFriendlyURLModelImpl.ENTITY_CACHE_ENABLED,
2524                            LayoutFriendlyURLModelImpl.FINDER_CACHE_ENABLED, Long.class,
2525                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByPlid",
2526                            new String[] { Long.class.getName() });
2527    
2528            /**
2529             * Returns all the layout friendly u r ls where plid = &#63;.
2530             *
2531             * @param plid the plid
2532             * @return the matching layout friendly u r ls
2533             */
2534            @Override
2535            public List<LayoutFriendlyURL> findByPlid(long plid) {
2536                    return findByPlid(plid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2537            }
2538    
2539            /**
2540             * Returns a range of all the layout friendly u r ls where plid = &#63;.
2541             *
2542             * <p>
2543             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link LayoutFriendlyURLModelImpl}. 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.
2544             * </p>
2545             *
2546             * @param plid the plid
2547             * @param start the lower bound of the range of layout friendly u r ls
2548             * @param end the upper bound of the range of layout friendly u r ls (not inclusive)
2549             * @return the range of matching layout friendly u r ls
2550             */
2551            @Override
2552            public List<LayoutFriendlyURL> findByPlid(long plid, int start, int end) {
2553                    return findByPlid(plid, start, end, null);
2554            }
2555    
2556            /**
2557             * Returns an ordered range of all the layout friendly u r ls where plid = &#63;.
2558             *
2559             * <p>
2560             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link LayoutFriendlyURLModelImpl}. 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.
2561             * </p>
2562             *
2563             * @param plid the plid
2564             * @param start the lower bound of the range of layout friendly u r ls
2565             * @param end the upper bound of the range of layout friendly u r ls (not inclusive)
2566             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2567             * @return the ordered range of matching layout friendly u r ls
2568             */
2569            @Override
2570            public List<LayoutFriendlyURL> findByPlid(long plid, int start, int end,
2571                    OrderByComparator<LayoutFriendlyURL> orderByComparator) {
2572                    return findByPlid(plid, start, end, orderByComparator, true);
2573            }
2574    
2575            /**
2576             * Returns an ordered range of all the layout friendly u r ls where plid = &#63;.
2577             *
2578             * <p>
2579             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link LayoutFriendlyURLModelImpl}. 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.
2580             * </p>
2581             *
2582             * @param plid the plid
2583             * @param start the lower bound of the range of layout friendly u r ls
2584             * @param end the upper bound of the range of layout friendly u r ls (not inclusive)
2585             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2586             * @param retrieveFromCache whether to retrieve from the finder cache
2587             * @return the ordered range of matching layout friendly u r ls
2588             */
2589            @Override
2590            public List<LayoutFriendlyURL> findByPlid(long plid, int start, int end,
2591                    OrderByComparator<LayoutFriendlyURL> orderByComparator,
2592                    boolean retrieveFromCache) {
2593                    boolean pagination = true;
2594                    FinderPath finderPath = null;
2595                    Object[] finderArgs = null;
2596    
2597                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2598                                    (orderByComparator == null)) {
2599                            pagination = false;
2600                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PLID;
2601                            finderArgs = new Object[] { plid };
2602                    }
2603                    else {
2604                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_PLID;
2605                            finderArgs = new Object[] { plid, start, end, orderByComparator };
2606                    }
2607    
2608                    List<LayoutFriendlyURL> list = null;
2609    
2610                    if (retrieveFromCache) {
2611                            list = (List<LayoutFriendlyURL>)finderCache.getResult(finderPath,
2612                                            finderArgs, this);
2613    
2614                            if ((list != null) && !list.isEmpty()) {
2615                                    for (LayoutFriendlyURL layoutFriendlyURL : list) {
2616                                            if ((plid != layoutFriendlyURL.getPlid())) {
2617                                                    list = null;
2618    
2619                                                    break;
2620                                            }
2621                                    }
2622                            }
2623                    }
2624    
2625                    if (list == null) {
2626                            StringBundler query = null;
2627    
2628                            if (orderByComparator != null) {
2629                                    query = new StringBundler(3 +
2630                                                    (orderByComparator.getOrderByFields().length * 2));
2631                            }
2632                            else {
2633                                    query = new StringBundler(3);
2634                            }
2635    
2636                            query.append(_SQL_SELECT_LAYOUTFRIENDLYURL_WHERE);
2637    
2638                            query.append(_FINDER_COLUMN_PLID_PLID_2);
2639    
2640                            if (orderByComparator != null) {
2641                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2642                                            orderByComparator);
2643                            }
2644                            else
2645                             if (pagination) {
2646                                    query.append(LayoutFriendlyURLModelImpl.ORDER_BY_JPQL);
2647                            }
2648    
2649                            String sql = query.toString();
2650    
2651                            Session session = null;
2652    
2653                            try {
2654                                    session = openSession();
2655    
2656                                    Query q = session.createQuery(sql);
2657    
2658                                    QueryPos qPos = QueryPos.getInstance(q);
2659    
2660                                    qPos.add(plid);
2661    
2662                                    if (!pagination) {
2663                                            list = (List<LayoutFriendlyURL>)QueryUtil.list(q,
2664                                                            getDialect(), start, end, false);
2665    
2666                                            Collections.sort(list);
2667    
2668                                            list = Collections.unmodifiableList(list);
2669                                    }
2670                                    else {
2671                                            list = (List<LayoutFriendlyURL>)QueryUtil.list(q,
2672                                                            getDialect(), start, end);
2673                                    }
2674    
2675                                    cacheResult(list);
2676    
2677                                    finderCache.putResult(finderPath, finderArgs, list);
2678                            }
2679                            catch (Exception e) {
2680                                    finderCache.removeResult(finderPath, finderArgs);
2681    
2682                                    throw processException(e);
2683                            }
2684                            finally {
2685                                    closeSession(session);
2686                            }
2687                    }
2688    
2689                    return list;
2690            }
2691    
2692            /**
2693             * Returns the first layout friendly u r l in the ordered set where plid = &#63;.
2694             *
2695             * @param plid the plid
2696             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2697             * @return the first matching layout friendly u r l
2698             * @throws NoSuchLayoutFriendlyURLException if a matching layout friendly u r l could not be found
2699             */
2700            @Override
2701            public LayoutFriendlyURL findByPlid_First(long plid,
2702                    OrderByComparator<LayoutFriendlyURL> orderByComparator)
2703                    throws NoSuchLayoutFriendlyURLException {
2704                    LayoutFriendlyURL layoutFriendlyURL = fetchByPlid_First(plid,
2705                                    orderByComparator);
2706    
2707                    if (layoutFriendlyURL != null) {
2708                            return layoutFriendlyURL;
2709                    }
2710    
2711                    StringBundler msg = new StringBundler(4);
2712    
2713                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2714    
2715                    msg.append("plid=");
2716                    msg.append(plid);
2717    
2718                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2719    
2720                    throw new NoSuchLayoutFriendlyURLException(msg.toString());
2721            }
2722    
2723            /**
2724             * Returns the first layout friendly u r l in the ordered set where plid = &#63;.
2725             *
2726             * @param plid the plid
2727             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2728             * @return the first matching layout friendly u r l, or <code>null</code> if a matching layout friendly u r l could not be found
2729             */
2730            @Override
2731            public LayoutFriendlyURL fetchByPlid_First(long plid,
2732                    OrderByComparator<LayoutFriendlyURL> orderByComparator) {
2733                    List<LayoutFriendlyURL> list = findByPlid(plid, 0, 1, orderByComparator);
2734    
2735                    if (!list.isEmpty()) {
2736                            return list.get(0);
2737                    }
2738    
2739                    return null;
2740            }
2741    
2742            /**
2743             * Returns the last layout friendly u r l in the ordered set where plid = &#63;.
2744             *
2745             * @param plid the plid
2746             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2747             * @return the last matching layout friendly u r l
2748             * @throws NoSuchLayoutFriendlyURLException if a matching layout friendly u r l could not be found
2749             */
2750            @Override
2751            public LayoutFriendlyURL findByPlid_Last(long plid,
2752                    OrderByComparator<LayoutFriendlyURL> orderByComparator)
2753                    throws NoSuchLayoutFriendlyURLException {
2754                    LayoutFriendlyURL layoutFriendlyURL = fetchByPlid_Last(plid,
2755                                    orderByComparator);
2756    
2757                    if (layoutFriendlyURL != null) {
2758                            return layoutFriendlyURL;
2759                    }
2760    
2761                    StringBundler msg = new StringBundler(4);
2762    
2763                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2764    
2765                    msg.append("plid=");
2766                    msg.append(plid);
2767    
2768                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2769    
2770                    throw new NoSuchLayoutFriendlyURLException(msg.toString());
2771            }
2772    
2773            /**
2774             * Returns the last layout friendly u r l in the ordered set where plid = &#63;.
2775             *
2776             * @param plid the plid
2777             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2778             * @return the last matching layout friendly u r l, or <code>null</code> if a matching layout friendly u r l could not be found
2779             */
2780            @Override
2781            public LayoutFriendlyURL fetchByPlid_Last(long plid,
2782                    OrderByComparator<LayoutFriendlyURL> orderByComparator) {
2783                    int count = countByPlid(plid);
2784    
2785                    if (count == 0) {
2786                            return null;
2787                    }
2788    
2789                    List<LayoutFriendlyURL> list = findByPlid(plid, count - 1, count,
2790                                    orderByComparator);
2791    
2792                    if (!list.isEmpty()) {
2793                            return list.get(0);
2794                    }
2795    
2796                    return null;
2797            }
2798    
2799            /**
2800             * Returns the layout friendly u r ls before and after the current layout friendly u r l in the ordered set where plid = &#63;.
2801             *
2802             * @param layoutFriendlyURLId the primary key of the current layout friendly u r l
2803             * @param plid the plid
2804             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2805             * @return the previous, current, and next layout friendly u r l
2806             * @throws NoSuchLayoutFriendlyURLException if a layout friendly u r l with the primary key could not be found
2807             */
2808            @Override
2809            public LayoutFriendlyURL[] findByPlid_PrevAndNext(
2810                    long layoutFriendlyURLId, long plid,
2811                    OrderByComparator<LayoutFriendlyURL> orderByComparator)
2812                    throws NoSuchLayoutFriendlyURLException {
2813                    LayoutFriendlyURL layoutFriendlyURL = findByPrimaryKey(layoutFriendlyURLId);
2814    
2815                    Session session = null;
2816    
2817                    try {
2818                            session = openSession();
2819    
2820                            LayoutFriendlyURL[] array = new LayoutFriendlyURLImpl[3];
2821    
2822                            array[0] = getByPlid_PrevAndNext(session, layoutFriendlyURL, plid,
2823                                            orderByComparator, true);
2824    
2825                            array[1] = layoutFriendlyURL;
2826    
2827                            array[2] = getByPlid_PrevAndNext(session, layoutFriendlyURL, plid,
2828                                            orderByComparator, false);
2829    
2830                            return array;
2831                    }
2832                    catch (Exception e) {
2833                            throw processException(e);
2834                    }
2835                    finally {
2836                            closeSession(session);
2837                    }
2838            }
2839    
2840            protected LayoutFriendlyURL getByPlid_PrevAndNext(Session session,
2841                    LayoutFriendlyURL layoutFriendlyURL, long plid,
2842                    OrderByComparator<LayoutFriendlyURL> orderByComparator, boolean previous) {
2843                    StringBundler query = null;
2844    
2845                    if (orderByComparator != null) {
2846                            query = new StringBundler(4 +
2847                                            (orderByComparator.getOrderByConditionFields().length * 3) +
2848                                            (orderByComparator.getOrderByFields().length * 3));
2849                    }
2850                    else {
2851                            query = new StringBundler(3);
2852                    }
2853    
2854                    query.append(_SQL_SELECT_LAYOUTFRIENDLYURL_WHERE);
2855    
2856                    query.append(_FINDER_COLUMN_PLID_PLID_2);
2857    
2858                    if (orderByComparator != null) {
2859                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2860    
2861                            if (orderByConditionFields.length > 0) {
2862                                    query.append(WHERE_AND);
2863                            }
2864    
2865                            for (int i = 0; i < orderByConditionFields.length; i++) {
2866                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2867                                    query.append(orderByConditionFields[i]);
2868    
2869                                    if ((i + 1) < orderByConditionFields.length) {
2870                                            if (orderByComparator.isAscending() ^ previous) {
2871                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2872                                            }
2873                                            else {
2874                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2875                                            }
2876                                    }
2877                                    else {
2878                                            if (orderByComparator.isAscending() ^ previous) {
2879                                                    query.append(WHERE_GREATER_THAN);
2880                                            }
2881                                            else {
2882                                                    query.append(WHERE_LESSER_THAN);
2883                                            }
2884                                    }
2885                            }
2886    
2887                            query.append(ORDER_BY_CLAUSE);
2888    
2889                            String[] orderByFields = orderByComparator.getOrderByFields();
2890    
2891                            for (int i = 0; i < orderByFields.length; i++) {
2892                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2893                                    query.append(orderByFields[i]);
2894    
2895                                    if ((i + 1) < orderByFields.length) {
2896                                            if (orderByComparator.isAscending() ^ previous) {
2897                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2898                                            }
2899                                            else {
2900                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2901                                            }
2902                                    }
2903                                    else {
2904                                            if (orderByComparator.isAscending() ^ previous) {
2905                                                    query.append(ORDER_BY_ASC);
2906                                            }
2907                                            else {
2908                                                    query.append(ORDER_BY_DESC);
2909                                            }
2910                                    }
2911                            }
2912                    }
2913                    else {
2914                            query.append(LayoutFriendlyURLModelImpl.ORDER_BY_JPQL);
2915                    }
2916    
2917                    String sql = query.toString();
2918    
2919                    Query q = session.createQuery(sql);
2920    
2921                    q.setFirstResult(0);
2922                    q.setMaxResults(2);
2923    
2924                    QueryPos qPos = QueryPos.getInstance(q);
2925    
2926                    qPos.add(plid);
2927    
2928                    if (orderByComparator != null) {
2929                            Object[] values = orderByComparator.getOrderByConditionValues(layoutFriendlyURL);
2930    
2931                            for (Object value : values) {
2932                                    qPos.add(value);
2933                            }
2934                    }
2935    
2936                    List<LayoutFriendlyURL> list = q.list();
2937    
2938                    if (list.size() == 2) {
2939                            return list.get(1);
2940                    }
2941                    else {
2942                            return null;
2943                    }
2944            }
2945    
2946            /**
2947             * Removes all the layout friendly u r ls where plid = &#63; from the database.
2948             *
2949             * @param plid the plid
2950             */
2951            @Override
2952            public void removeByPlid(long plid) {
2953                    for (LayoutFriendlyURL layoutFriendlyURL : findByPlid(plid,
2954                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2955                            remove(layoutFriendlyURL);
2956                    }
2957            }
2958    
2959            /**
2960             * Returns the number of layout friendly u r ls where plid = &#63;.
2961             *
2962             * @param plid the plid
2963             * @return the number of matching layout friendly u r ls
2964             */
2965            @Override
2966            public int countByPlid(long plid) {
2967                    FinderPath finderPath = FINDER_PATH_COUNT_BY_PLID;
2968    
2969                    Object[] finderArgs = new Object[] { plid };
2970    
2971                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
2972    
2973                    if (count == null) {
2974                            StringBundler query = new StringBundler(2);
2975    
2976                            query.append(_SQL_COUNT_LAYOUTFRIENDLYURL_WHERE);
2977    
2978                            query.append(_FINDER_COLUMN_PLID_PLID_2);
2979    
2980                            String sql = query.toString();
2981    
2982                            Session session = null;
2983    
2984                            try {
2985                                    session = openSession();
2986    
2987                                    Query q = session.createQuery(sql);
2988    
2989                                    QueryPos qPos = QueryPos.getInstance(q);
2990    
2991                                    qPos.add(plid);
2992    
2993                                    count = (Long)q.uniqueResult();
2994    
2995                                    finderCache.putResult(finderPath, finderArgs, count);
2996                            }
2997                            catch (Exception e) {
2998                                    finderCache.removeResult(finderPath, finderArgs);
2999    
3000                                    throw processException(e);
3001                            }
3002                            finally {
3003                                    closeSession(session);
3004                            }
3005                    }
3006    
3007                    return count.intValue();
3008            }
3009    
3010            private static final String _FINDER_COLUMN_PLID_PLID_2 = "layoutFriendlyURL.plid = ?";
3011            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_P_F = new FinderPath(LayoutFriendlyURLModelImpl.ENTITY_CACHE_ENABLED,
3012                            LayoutFriendlyURLModelImpl.FINDER_CACHE_ENABLED,
3013                            LayoutFriendlyURLImpl.class,
3014                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByP_F",
3015                            new String[] {
3016                                    Long.class.getName(), String.class.getName(),
3017                                    
3018                            Integer.class.getName(), Integer.class.getName(),
3019                                    OrderByComparator.class.getName()
3020                            });
3021            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_F = new FinderPath(LayoutFriendlyURLModelImpl.ENTITY_CACHE_ENABLED,
3022                            LayoutFriendlyURLModelImpl.FINDER_CACHE_ENABLED,
3023                            LayoutFriendlyURLImpl.class,
3024                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByP_F",
3025                            new String[] { Long.class.getName(), String.class.getName() },
3026                            LayoutFriendlyURLModelImpl.PLID_COLUMN_BITMASK |
3027                            LayoutFriendlyURLModelImpl.FRIENDLYURL_COLUMN_BITMASK);
3028            public static final FinderPath FINDER_PATH_COUNT_BY_P_F = new FinderPath(LayoutFriendlyURLModelImpl.ENTITY_CACHE_ENABLED,
3029                            LayoutFriendlyURLModelImpl.FINDER_CACHE_ENABLED, Long.class,
3030                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByP_F",
3031                            new String[] { Long.class.getName(), String.class.getName() });
3032    
3033            /**
3034             * Returns all the layout friendly u r ls where plid = &#63; and friendlyURL = &#63;.
3035             *
3036             * @param plid the plid
3037             * @param friendlyURL the friendly u r l
3038             * @return the matching layout friendly u r ls
3039             */
3040            @Override
3041            public List<LayoutFriendlyURL> findByP_F(long plid, String friendlyURL) {
3042                    return findByP_F(plid, friendlyURL, QueryUtil.ALL_POS,
3043                            QueryUtil.ALL_POS, null);
3044            }
3045    
3046            /**
3047             * Returns a range of all the layout friendly u r ls where plid = &#63; and friendlyURL = &#63;.
3048             *
3049             * <p>
3050             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link LayoutFriendlyURLModelImpl}. 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.
3051             * </p>
3052             *
3053             * @param plid the plid
3054             * @param friendlyURL the friendly u r l
3055             * @param start the lower bound of the range of layout friendly u r ls
3056             * @param end the upper bound of the range of layout friendly u r ls (not inclusive)
3057             * @return the range of matching layout friendly u r ls
3058             */
3059            @Override
3060            public List<LayoutFriendlyURL> findByP_F(long plid, String friendlyURL,
3061                    int start, int end) {
3062                    return findByP_F(plid, friendlyURL, start, end, null);
3063            }
3064    
3065            /**
3066             * Returns an ordered range of all the layout friendly u r ls where plid = &#63; and friendlyURL = &#63;.
3067             *
3068             * <p>
3069             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link LayoutFriendlyURLModelImpl}. 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.
3070             * </p>
3071             *
3072             * @param plid the plid
3073             * @param friendlyURL the friendly u r l
3074             * @param start the lower bound of the range of layout friendly u r ls
3075             * @param end the upper bound of the range of layout friendly u r ls (not inclusive)
3076             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3077             * @return the ordered range of matching layout friendly u r ls
3078             */
3079            @Override
3080            public List<LayoutFriendlyURL> findByP_F(long plid, String friendlyURL,
3081                    int start, int end,
3082                    OrderByComparator<LayoutFriendlyURL> orderByComparator) {
3083                    return findByP_F(plid, friendlyURL, start, end, orderByComparator, true);
3084            }
3085    
3086            /**
3087             * Returns an ordered range of all the layout friendly u r ls where plid = &#63; and friendlyURL = &#63;.
3088             *
3089             * <p>
3090             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link LayoutFriendlyURLModelImpl}. 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.
3091             * </p>
3092             *
3093             * @param plid the plid
3094             * @param friendlyURL the friendly u r l
3095             * @param start the lower bound of the range of layout friendly u r ls
3096             * @param end the upper bound of the range of layout friendly u r ls (not inclusive)
3097             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3098             * @param retrieveFromCache whether to retrieve from the finder cache
3099             * @return the ordered range of matching layout friendly u r ls
3100             */
3101            @Override
3102            public List<LayoutFriendlyURL> findByP_F(long plid, String friendlyURL,
3103                    int start, int end,
3104                    OrderByComparator<LayoutFriendlyURL> orderByComparator,
3105                    boolean retrieveFromCache) {
3106                    boolean pagination = true;
3107                    FinderPath finderPath = null;
3108                    Object[] finderArgs = null;
3109    
3110                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3111                                    (orderByComparator == null)) {
3112                            pagination = false;
3113                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_F;
3114                            finderArgs = new Object[] { plid, friendlyURL };
3115                    }
3116                    else {
3117                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_P_F;
3118                            finderArgs = new Object[] {
3119                                            plid, friendlyURL,
3120                                            
3121                                            start, end, orderByComparator
3122                                    };
3123                    }
3124    
3125                    List<LayoutFriendlyURL> list = null;
3126    
3127                    if (retrieveFromCache) {
3128                            list = (List<LayoutFriendlyURL>)finderCache.getResult(finderPath,
3129                                            finderArgs, this);
3130    
3131                            if ((list != null) && !list.isEmpty()) {
3132                                    for (LayoutFriendlyURL layoutFriendlyURL : list) {
3133                                            if ((plid != layoutFriendlyURL.getPlid()) ||
3134                                                            !Objects.equals(friendlyURL,
3135                                                                    layoutFriendlyURL.getFriendlyURL())) {
3136                                                    list = null;
3137    
3138                                                    break;
3139                                            }
3140                                    }
3141                            }
3142                    }
3143    
3144                    if (list == null) {
3145                            StringBundler query = null;
3146    
3147                            if (orderByComparator != null) {
3148                                    query = new StringBundler(4 +
3149                                                    (orderByComparator.getOrderByFields().length * 2));
3150                            }
3151                            else {
3152                                    query = new StringBundler(4);
3153                            }
3154    
3155                            query.append(_SQL_SELECT_LAYOUTFRIENDLYURL_WHERE);
3156    
3157                            query.append(_FINDER_COLUMN_P_F_PLID_2);
3158    
3159                            boolean bindFriendlyURL = false;
3160    
3161                            if (friendlyURL == null) {
3162                                    query.append(_FINDER_COLUMN_P_F_FRIENDLYURL_1);
3163                            }
3164                            else if (friendlyURL.equals(StringPool.BLANK)) {
3165                                    query.append(_FINDER_COLUMN_P_F_FRIENDLYURL_3);
3166                            }
3167                            else {
3168                                    bindFriendlyURL = true;
3169    
3170                                    query.append(_FINDER_COLUMN_P_F_FRIENDLYURL_2);
3171                            }
3172    
3173                            if (orderByComparator != null) {
3174                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3175                                            orderByComparator);
3176                            }
3177                            else
3178                             if (pagination) {
3179                                    query.append(LayoutFriendlyURLModelImpl.ORDER_BY_JPQL);
3180                            }
3181    
3182                            String sql = query.toString();
3183    
3184                            Session session = null;
3185    
3186                            try {
3187                                    session = openSession();
3188    
3189                                    Query q = session.createQuery(sql);
3190    
3191                                    QueryPos qPos = QueryPos.getInstance(q);
3192    
3193                                    qPos.add(plid);
3194    
3195                                    if (bindFriendlyURL) {
3196                                            qPos.add(friendlyURL);
3197                                    }
3198    
3199                                    if (!pagination) {
3200                                            list = (List<LayoutFriendlyURL>)QueryUtil.list(q,
3201                                                            getDialect(), start, end, false);
3202    
3203                                            Collections.sort(list);
3204    
3205                                            list = Collections.unmodifiableList(list);
3206                                    }
3207                                    else {
3208                                            list = (List<LayoutFriendlyURL>)QueryUtil.list(q,
3209                                                            getDialect(), start, end);
3210                                    }
3211    
3212                                    cacheResult(list);
3213    
3214                                    finderCache.putResult(finderPath, finderArgs, list);
3215                            }
3216                            catch (Exception e) {
3217                                    finderCache.removeResult(finderPath, finderArgs);
3218    
3219                                    throw processException(e);
3220                            }
3221                            finally {
3222                                    closeSession(session);
3223                            }
3224                    }
3225    
3226                    return list;
3227            }
3228    
3229            /**
3230             * Returns the first layout friendly u r l in the ordered set where plid = &#63; and friendlyURL = &#63;.
3231             *
3232             * @param plid the plid
3233             * @param friendlyURL the friendly u r l
3234             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3235             * @return the first matching layout friendly u r l
3236             * @throws NoSuchLayoutFriendlyURLException if a matching layout friendly u r l could not be found
3237             */
3238            @Override
3239            public LayoutFriendlyURL findByP_F_First(long plid, String friendlyURL,
3240                    OrderByComparator<LayoutFriendlyURL> orderByComparator)
3241                    throws NoSuchLayoutFriendlyURLException {
3242                    LayoutFriendlyURL layoutFriendlyURL = fetchByP_F_First(plid,
3243                                    friendlyURL, orderByComparator);
3244    
3245                    if (layoutFriendlyURL != null) {
3246                            return layoutFriendlyURL;
3247                    }
3248    
3249                    StringBundler msg = new StringBundler(6);
3250    
3251                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3252    
3253                    msg.append("plid=");
3254                    msg.append(plid);
3255    
3256                    msg.append(", friendlyURL=");
3257                    msg.append(friendlyURL);
3258    
3259                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3260    
3261                    throw new NoSuchLayoutFriendlyURLException(msg.toString());
3262            }
3263    
3264            /**
3265             * Returns the first layout friendly u r l in the ordered set where plid = &#63; and friendlyURL = &#63;.
3266             *
3267             * @param plid the plid
3268             * @param friendlyURL the friendly u r l
3269             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3270             * @return the first matching layout friendly u r l, or <code>null</code> if a matching layout friendly u r l could not be found
3271             */
3272            @Override
3273            public LayoutFriendlyURL fetchByP_F_First(long plid, String friendlyURL,
3274                    OrderByComparator<LayoutFriendlyURL> orderByComparator) {
3275                    List<LayoutFriendlyURL> list = findByP_F(plid, friendlyURL, 0, 1,
3276                                    orderByComparator);
3277    
3278                    if (!list.isEmpty()) {
3279                            return list.get(0);
3280                    }
3281    
3282                    return null;
3283            }
3284    
3285            /**
3286             * Returns the last layout friendly u r l in the ordered set where plid = &#63; and friendlyURL = &#63;.
3287             *
3288             * @param plid the plid
3289             * @param friendlyURL the friendly u r l
3290             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3291             * @return the last matching layout friendly u r l
3292             * @throws NoSuchLayoutFriendlyURLException if a matching layout friendly u r l could not be found
3293             */
3294            @Override
3295            public LayoutFriendlyURL findByP_F_Last(long plid, String friendlyURL,
3296                    OrderByComparator<LayoutFriendlyURL> orderByComparator)
3297                    throws NoSuchLayoutFriendlyURLException {
3298                    LayoutFriendlyURL layoutFriendlyURL = fetchByP_F_Last(plid,
3299                                    friendlyURL, orderByComparator);
3300    
3301                    if (layoutFriendlyURL != null) {
3302                            return layoutFriendlyURL;
3303                    }
3304    
3305                    StringBundler msg = new StringBundler(6);
3306    
3307                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3308    
3309                    msg.append("plid=");
3310                    msg.append(plid);
3311    
3312                    msg.append(", friendlyURL=");
3313                    msg.append(friendlyURL);
3314    
3315                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3316    
3317                    throw new NoSuchLayoutFriendlyURLException(msg.toString());
3318            }
3319    
3320            /**
3321             * Returns the last layout friendly u r l in the ordered set where plid = &#63; and friendlyURL = &#63;.
3322             *
3323             * @param plid the plid
3324             * @param friendlyURL the friendly u r l
3325             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3326             * @return the last matching layout friendly u r l, or <code>null</code> if a matching layout friendly u r l could not be found
3327             */
3328            @Override
3329            public LayoutFriendlyURL fetchByP_F_Last(long plid, String friendlyURL,
3330                    OrderByComparator<LayoutFriendlyURL> orderByComparator) {
3331                    int count = countByP_F(plid, friendlyURL);
3332    
3333                    if (count == 0) {
3334                            return null;
3335                    }
3336    
3337                    List<LayoutFriendlyURL> list = findByP_F(plid, friendlyURL, count - 1,
3338                                    count, orderByComparator);
3339    
3340                    if (!list.isEmpty()) {
3341                            return list.get(0);
3342                    }
3343    
3344                    return null;
3345            }
3346    
3347            /**
3348             * Returns the layout friendly u r ls before and after the current layout friendly u r l in the ordered set where plid = &#63; and friendlyURL = &#63;.
3349             *
3350             * @param layoutFriendlyURLId the primary key of the current layout friendly u r l
3351             * @param plid the plid
3352             * @param friendlyURL the friendly u r l
3353             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3354             * @return the previous, current, and next layout friendly u r l
3355             * @throws NoSuchLayoutFriendlyURLException if a layout friendly u r l with the primary key could not be found
3356             */
3357            @Override
3358            public LayoutFriendlyURL[] findByP_F_PrevAndNext(long layoutFriendlyURLId,
3359                    long plid, String friendlyURL,
3360                    OrderByComparator<LayoutFriendlyURL> orderByComparator)
3361                    throws NoSuchLayoutFriendlyURLException {
3362                    LayoutFriendlyURL layoutFriendlyURL = findByPrimaryKey(layoutFriendlyURLId);
3363    
3364                    Session session = null;
3365    
3366                    try {
3367                            session = openSession();
3368    
3369                            LayoutFriendlyURL[] array = new LayoutFriendlyURLImpl[3];
3370    
3371                            array[0] = getByP_F_PrevAndNext(session, layoutFriendlyURL, plid,
3372                                            friendlyURL, orderByComparator, true);
3373    
3374                            array[1] = layoutFriendlyURL;
3375    
3376                            array[2] = getByP_F_PrevAndNext(session, layoutFriendlyURL, plid,
3377                                            friendlyURL, orderByComparator, false);
3378    
3379                            return array;
3380                    }
3381                    catch (Exception e) {
3382                            throw processException(e);
3383                    }
3384                    finally {
3385                            closeSession(session);
3386                    }
3387            }
3388    
3389            protected LayoutFriendlyURL getByP_F_PrevAndNext(Session session,
3390                    LayoutFriendlyURL layoutFriendlyURL, long plid, String friendlyURL,
3391                    OrderByComparator<LayoutFriendlyURL> orderByComparator, boolean previous) {
3392                    StringBundler query = null;
3393    
3394                    if (orderByComparator != null) {
3395                            query = new StringBundler(5 +
3396                                            (orderByComparator.getOrderByConditionFields().length * 3) +
3397                                            (orderByComparator.getOrderByFields().length * 3));
3398                    }
3399                    else {
3400                            query = new StringBundler(4);
3401                    }
3402    
3403                    query.append(_SQL_SELECT_LAYOUTFRIENDLYURL_WHERE);
3404    
3405                    query.append(_FINDER_COLUMN_P_F_PLID_2);
3406    
3407                    boolean bindFriendlyURL = false;
3408    
3409                    if (friendlyURL == null) {
3410                            query.append(_FINDER_COLUMN_P_F_FRIENDLYURL_1);
3411                    }
3412                    else if (friendlyURL.equals(StringPool.BLANK)) {
3413                            query.append(_FINDER_COLUMN_P_F_FRIENDLYURL_3);
3414                    }
3415                    else {
3416                            bindFriendlyURL = true;
3417    
3418                            query.append(_FINDER_COLUMN_P_F_FRIENDLYURL_2);
3419                    }
3420    
3421                    if (orderByComparator != null) {
3422                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3423    
3424                            if (orderByConditionFields.length > 0) {
3425                                    query.append(WHERE_AND);
3426                            }
3427    
3428                            for (int i = 0; i < orderByConditionFields.length; i++) {
3429                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3430                                    query.append(orderByConditionFields[i]);
3431    
3432                                    if ((i + 1) < orderByConditionFields.length) {
3433                                            if (orderByComparator.isAscending() ^ previous) {
3434                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3435                                            }
3436                                            else {
3437                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3438                                            }
3439                                    }
3440                                    else {
3441                                            if (orderByComparator.isAscending() ^ previous) {
3442                                                    query.append(WHERE_GREATER_THAN);
3443                                            }
3444                                            else {
3445                                                    query.append(WHERE_LESSER_THAN);
3446                                            }
3447                                    }
3448                            }
3449    
3450                            query.append(ORDER_BY_CLAUSE);
3451    
3452                            String[] orderByFields = orderByComparator.getOrderByFields();
3453    
3454                            for (int i = 0; i < orderByFields.length; i++) {
3455                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3456                                    query.append(orderByFields[i]);
3457    
3458                                    if ((i + 1) < orderByFields.length) {
3459                                            if (orderByComparator.isAscending() ^ previous) {
3460                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3461                                            }
3462                                            else {
3463                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3464                                            }
3465                                    }
3466                                    else {
3467                                            if (orderByComparator.isAscending() ^ previous) {
3468                                                    query.append(ORDER_BY_ASC);
3469                                            }
3470                                            else {
3471                                                    query.append(ORDER_BY_DESC);
3472                                            }
3473                                    }
3474                            }
3475                    }
3476                    else {
3477                            query.append(LayoutFriendlyURLModelImpl.ORDER_BY_JPQL);
3478                    }
3479    
3480                    String sql = query.toString();
3481    
3482                    Query q = session.createQuery(sql);
3483    
3484                    q.setFirstResult(0);
3485                    q.setMaxResults(2);
3486    
3487                    QueryPos qPos = QueryPos.getInstance(q);
3488    
3489                    qPos.add(plid);
3490    
3491                    if (bindFriendlyURL) {
3492                            qPos.add(friendlyURL);
3493                    }
3494    
3495                    if (orderByComparator != null) {
3496                            Object[] values = orderByComparator.getOrderByConditionValues(layoutFriendlyURL);
3497    
3498                            for (Object value : values) {
3499                                    qPos.add(value);
3500                            }
3501                    }
3502    
3503                    List<LayoutFriendlyURL> list = q.list();
3504    
3505                    if (list.size() == 2) {
3506                            return list.get(1);
3507                    }
3508                    else {
3509                            return null;
3510                    }
3511            }
3512    
3513            /**
3514             * Removes all the layout friendly u r ls where plid = &#63; and friendlyURL = &#63; from the database.
3515             *
3516             * @param plid the plid
3517             * @param friendlyURL the friendly u r l
3518             */
3519            @Override
3520            public void removeByP_F(long plid, String friendlyURL) {
3521                    for (LayoutFriendlyURL layoutFriendlyURL : findByP_F(plid, friendlyURL,
3522                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3523                            remove(layoutFriendlyURL);
3524                    }
3525            }
3526    
3527            /**
3528             * Returns the number of layout friendly u r ls where plid = &#63; and friendlyURL = &#63;.
3529             *
3530             * @param plid the plid
3531             * @param friendlyURL the friendly u r l
3532             * @return the number of matching layout friendly u r ls
3533             */
3534            @Override
3535            public int countByP_F(long plid, String friendlyURL) {
3536                    FinderPath finderPath = FINDER_PATH_COUNT_BY_P_F;
3537    
3538                    Object[] finderArgs = new Object[] { plid, friendlyURL };
3539    
3540                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
3541    
3542                    if (count == null) {
3543                            StringBundler query = new StringBundler(3);
3544    
3545                            query.append(_SQL_COUNT_LAYOUTFRIENDLYURL_WHERE);
3546    
3547                            query.append(_FINDER_COLUMN_P_F_PLID_2);
3548    
3549                            boolean bindFriendlyURL = false;
3550    
3551                            if (friendlyURL == null) {
3552                                    query.append(_FINDER_COLUMN_P_F_FRIENDLYURL_1);
3553                            }
3554                            else if (friendlyURL.equals(StringPool.BLANK)) {
3555                                    query.append(_FINDER_COLUMN_P_F_FRIENDLYURL_3);
3556                            }
3557                            else {
3558                                    bindFriendlyURL = true;
3559    
3560                                    query.append(_FINDER_COLUMN_P_F_FRIENDLYURL_2);
3561                            }
3562    
3563                            String sql = query.toString();
3564    
3565                            Session session = null;
3566    
3567                            try {
3568                                    session = openSession();
3569    
3570                                    Query q = session.createQuery(sql);
3571    
3572                                    QueryPos qPos = QueryPos.getInstance(q);
3573    
3574                                    qPos.add(plid);
3575    
3576                                    if (bindFriendlyURL) {
3577                                            qPos.add(friendlyURL);
3578                                    }
3579    
3580                                    count = (Long)q.uniqueResult();
3581    
3582                                    finderCache.putResult(finderPath, finderArgs, count);
3583                            }
3584                            catch (Exception e) {
3585                                    finderCache.removeResult(finderPath, finderArgs);
3586    
3587                                    throw processException(e);
3588                            }
3589                            finally {
3590                                    closeSession(session);
3591                            }
3592                    }
3593    
3594                    return count.intValue();
3595            }
3596    
3597            private static final String _FINDER_COLUMN_P_F_PLID_2 = "layoutFriendlyURL.plid = ? AND ";
3598            private static final String _FINDER_COLUMN_P_F_FRIENDLYURL_1 = "layoutFriendlyURL.friendlyURL IS NULL";
3599            private static final String _FINDER_COLUMN_P_F_FRIENDLYURL_2 = "layoutFriendlyURL.friendlyURL = ?";
3600            private static final String _FINDER_COLUMN_P_F_FRIENDLYURL_3 = "(layoutFriendlyURL.friendlyURL IS NULL OR layoutFriendlyURL.friendlyURL = '')";
3601            public static final FinderPath FINDER_PATH_FETCH_BY_P_L = new FinderPath(LayoutFriendlyURLModelImpl.ENTITY_CACHE_ENABLED,
3602                            LayoutFriendlyURLModelImpl.FINDER_CACHE_ENABLED,
3603                            LayoutFriendlyURLImpl.class, FINDER_CLASS_NAME_ENTITY,
3604                            "fetchByP_L",
3605                            new String[] { Long.class.getName(), String.class.getName() },
3606                            LayoutFriendlyURLModelImpl.PLID_COLUMN_BITMASK |
3607                            LayoutFriendlyURLModelImpl.LANGUAGEID_COLUMN_BITMASK);
3608            public static final FinderPath FINDER_PATH_COUNT_BY_P_L = new FinderPath(LayoutFriendlyURLModelImpl.ENTITY_CACHE_ENABLED,
3609                            LayoutFriendlyURLModelImpl.FINDER_CACHE_ENABLED, Long.class,
3610                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByP_L",
3611                            new String[] { Long.class.getName(), String.class.getName() });
3612    
3613            /**
3614             * Returns the layout friendly u r l where plid = &#63; and languageId = &#63; or throws a {@link NoSuchLayoutFriendlyURLException} if it could not be found.
3615             *
3616             * @param plid the plid
3617             * @param languageId the language ID
3618             * @return the matching layout friendly u r l
3619             * @throws NoSuchLayoutFriendlyURLException if a matching layout friendly u r l could not be found
3620             */
3621            @Override
3622            public LayoutFriendlyURL findByP_L(long plid, String languageId)
3623                    throws NoSuchLayoutFriendlyURLException {
3624                    LayoutFriendlyURL layoutFriendlyURL = fetchByP_L(plid, languageId);
3625    
3626                    if (layoutFriendlyURL == null) {
3627                            StringBundler msg = new StringBundler(6);
3628    
3629                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3630    
3631                            msg.append("plid=");
3632                            msg.append(plid);
3633    
3634                            msg.append(", languageId=");
3635                            msg.append(languageId);
3636    
3637                            msg.append(StringPool.CLOSE_CURLY_BRACE);
3638    
3639                            if (_log.isDebugEnabled()) {
3640                                    _log.debug(msg.toString());
3641                            }
3642    
3643                            throw new NoSuchLayoutFriendlyURLException(msg.toString());
3644                    }
3645    
3646                    return layoutFriendlyURL;
3647            }
3648    
3649            /**
3650             * Returns the layout friendly u r l where plid = &#63; and languageId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
3651             *
3652             * @param plid the plid
3653             * @param languageId the language ID
3654             * @return the matching layout friendly u r l, or <code>null</code> if a matching layout friendly u r l could not be found
3655             */
3656            @Override
3657            public LayoutFriendlyURL fetchByP_L(long plid, String languageId) {
3658                    return fetchByP_L(plid, languageId, true);
3659            }
3660    
3661            /**
3662             * Returns the layout friendly u r l where plid = &#63; and languageId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
3663             *
3664             * @param plid the plid
3665             * @param languageId the language ID
3666             * @param retrieveFromCache whether to retrieve from the finder cache
3667             * @return the matching layout friendly u r l, or <code>null</code> if a matching layout friendly u r l could not be found
3668             */
3669            @Override
3670            public LayoutFriendlyURL fetchByP_L(long plid, String languageId,
3671                    boolean retrieveFromCache) {
3672                    Object[] finderArgs = new Object[] { plid, languageId };
3673    
3674                    Object result = null;
3675    
3676                    if (retrieveFromCache) {
3677                            result = finderCache.getResult(FINDER_PATH_FETCH_BY_P_L,
3678                                            finderArgs, this);
3679                    }
3680    
3681                    if (result instanceof LayoutFriendlyURL) {
3682                            LayoutFriendlyURL layoutFriendlyURL = (LayoutFriendlyURL)result;
3683    
3684                            if ((plid != layoutFriendlyURL.getPlid()) ||
3685                                            !Objects.equals(languageId,
3686                                                    layoutFriendlyURL.getLanguageId())) {
3687                                    result = null;
3688                            }
3689                    }
3690    
3691                    if (result == null) {
3692                            StringBundler query = new StringBundler(4);
3693    
3694                            query.append(_SQL_SELECT_LAYOUTFRIENDLYURL_WHERE);
3695    
3696                            query.append(_FINDER_COLUMN_P_L_PLID_2);
3697    
3698                            boolean bindLanguageId = false;
3699    
3700                            if (languageId == null) {
3701                                    query.append(_FINDER_COLUMN_P_L_LANGUAGEID_1);
3702                            }
3703                            else if (languageId.equals(StringPool.BLANK)) {
3704                                    query.append(_FINDER_COLUMN_P_L_LANGUAGEID_3);
3705                            }
3706                            else {
3707                                    bindLanguageId = true;
3708    
3709                                    query.append(_FINDER_COLUMN_P_L_LANGUAGEID_2);
3710                            }
3711    
3712                            String sql = query.toString();
3713    
3714                            Session session = null;
3715    
3716                            try {
3717                                    session = openSession();
3718    
3719                                    Query q = session.createQuery(sql);
3720    
3721                                    QueryPos qPos = QueryPos.getInstance(q);
3722    
3723                                    qPos.add(plid);
3724    
3725                                    if (bindLanguageId) {
3726                                            qPos.add(languageId);
3727                                    }
3728    
3729                                    List<LayoutFriendlyURL> list = q.list();
3730    
3731                                    if (list.isEmpty()) {
3732                                            finderCache.putResult(FINDER_PATH_FETCH_BY_P_L, finderArgs,
3733                                                    list);
3734                                    }
3735                                    else {
3736                                            LayoutFriendlyURL layoutFriendlyURL = list.get(0);
3737    
3738                                            result = layoutFriendlyURL;
3739    
3740                                            cacheResult(layoutFriendlyURL);
3741    
3742                                            if ((layoutFriendlyURL.getPlid() != plid) ||
3743                                                            (layoutFriendlyURL.getLanguageId() == null) ||
3744                                                            !layoutFriendlyURL.getLanguageId().equals(languageId)) {
3745                                                    finderCache.putResult(FINDER_PATH_FETCH_BY_P_L,
3746                                                            finderArgs, layoutFriendlyURL);
3747                                            }
3748                                    }
3749                            }
3750                            catch (Exception e) {
3751                                    finderCache.removeResult(FINDER_PATH_FETCH_BY_P_L, finderArgs);
3752    
3753                                    throw processException(e);
3754                            }
3755                            finally {
3756                                    closeSession(session);
3757                            }
3758                    }
3759    
3760                    if (result instanceof List<?>) {
3761                            return null;
3762                    }
3763                    else {
3764                            return (LayoutFriendlyURL)result;
3765                    }
3766            }
3767    
3768            /**
3769             * Removes the layout friendly u r l where plid = &#63; and languageId = &#63; from the database.
3770             *
3771             * @param plid the plid
3772             * @param languageId the language ID
3773             * @return the layout friendly u r l that was removed
3774             */
3775            @Override
3776            public LayoutFriendlyURL removeByP_L(long plid, String languageId)
3777                    throws NoSuchLayoutFriendlyURLException {
3778                    LayoutFriendlyURL layoutFriendlyURL = findByP_L(plid, languageId);
3779    
3780                    return remove(layoutFriendlyURL);
3781            }
3782    
3783            /**
3784             * Returns the number of layout friendly u r ls where plid = &#63; and languageId = &#63;.
3785             *
3786             * @param plid the plid
3787             * @param languageId the language ID
3788             * @return the number of matching layout friendly u r ls
3789             */
3790            @Override
3791            public int countByP_L(long plid, String languageId) {
3792                    FinderPath finderPath = FINDER_PATH_COUNT_BY_P_L;
3793    
3794                    Object[] finderArgs = new Object[] { plid, languageId };
3795    
3796                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
3797    
3798                    if (count == null) {
3799                            StringBundler query = new StringBundler(3);
3800    
3801                            query.append(_SQL_COUNT_LAYOUTFRIENDLYURL_WHERE);
3802    
3803                            query.append(_FINDER_COLUMN_P_L_PLID_2);
3804    
3805                            boolean bindLanguageId = false;
3806    
3807                            if (languageId == null) {
3808                                    query.append(_FINDER_COLUMN_P_L_LANGUAGEID_1);
3809                            }
3810                            else if (languageId.equals(StringPool.BLANK)) {
3811                                    query.append(_FINDER_COLUMN_P_L_LANGUAGEID_3);
3812                            }
3813                            else {
3814                                    bindLanguageId = true;
3815    
3816                                    query.append(_FINDER_COLUMN_P_L_LANGUAGEID_2);
3817                            }
3818    
3819                            String sql = query.toString();
3820    
3821                            Session session = null;
3822    
3823                            try {
3824                                    session = openSession();
3825    
3826                                    Query q = session.createQuery(sql);
3827    
3828                                    QueryPos qPos = QueryPos.getInstance(q);
3829    
3830                                    qPos.add(plid);
3831    
3832                                    if (bindLanguageId) {
3833                                            qPos.add(languageId);
3834                                    }
3835    
3836                                    count = (Long)q.uniqueResult();
3837    
3838                                    finderCache.putResult(finderPath, finderArgs, count);
3839                            }
3840                            catch (Exception e) {
3841                                    finderCache.removeResult(finderPath, finderArgs);
3842    
3843                                    throw processException(e);
3844                            }
3845                            finally {
3846                                    closeSession(session);
3847                            }
3848                    }
3849    
3850                    return count.intValue();
3851            }
3852    
3853            private static final String _FINDER_COLUMN_P_L_PLID_2 = "layoutFriendlyURL.plid = ? AND ";
3854            private static final String _FINDER_COLUMN_P_L_LANGUAGEID_1 = "layoutFriendlyURL.languageId IS NULL";
3855            private static final String _FINDER_COLUMN_P_L_LANGUAGEID_2 = "layoutFriendlyURL.languageId = ?";
3856            private static final String _FINDER_COLUMN_P_L_LANGUAGEID_3 = "(layoutFriendlyURL.languageId IS NULL OR layoutFriendlyURL.languageId = '')";
3857            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_F = new FinderPath(LayoutFriendlyURLModelImpl.ENTITY_CACHE_ENABLED,
3858                            LayoutFriendlyURLModelImpl.FINDER_CACHE_ENABLED,
3859                            LayoutFriendlyURLImpl.class,
3860                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_P_F",
3861                            new String[] {
3862                                    Long.class.getName(), Boolean.class.getName(),
3863                                    String.class.getName(),
3864                                    
3865                            Integer.class.getName(), Integer.class.getName(),
3866                                    OrderByComparator.class.getName()
3867                            });
3868            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_F = new FinderPath(LayoutFriendlyURLModelImpl.ENTITY_CACHE_ENABLED,
3869                            LayoutFriendlyURLModelImpl.FINDER_CACHE_ENABLED,
3870                            LayoutFriendlyURLImpl.class,
3871                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_P_F",
3872                            new String[] {
3873                                    Long.class.getName(), Boolean.class.getName(),
3874                                    String.class.getName()
3875                            },
3876                            LayoutFriendlyURLModelImpl.GROUPID_COLUMN_BITMASK |
3877                            LayoutFriendlyURLModelImpl.PRIVATELAYOUT_COLUMN_BITMASK |
3878                            LayoutFriendlyURLModelImpl.FRIENDLYURL_COLUMN_BITMASK);
3879            public static final FinderPath FINDER_PATH_COUNT_BY_G_P_F = new FinderPath(LayoutFriendlyURLModelImpl.ENTITY_CACHE_ENABLED,
3880                            LayoutFriendlyURLModelImpl.FINDER_CACHE_ENABLED, Long.class,
3881                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P_F",
3882                            new String[] {
3883                                    Long.class.getName(), Boolean.class.getName(),
3884                                    String.class.getName()
3885                            });
3886    
3887            /**
3888             * Returns all the layout friendly u r ls where groupId = &#63; and privateLayout = &#63; and friendlyURL = &#63;.
3889             *
3890             * @param groupId the group ID
3891             * @param privateLayout the private layout
3892             * @param friendlyURL the friendly u r l
3893             * @return the matching layout friendly u r ls
3894             */
3895            @Override
3896            public List<LayoutFriendlyURL> findByG_P_F(long groupId,
3897                    boolean privateLayout, String friendlyURL) {
3898                    return findByG_P_F(groupId, privateLayout, friendlyURL,
3899                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3900            }
3901    
3902            /**
3903             * Returns a range of all the layout friendly u r ls where groupId = &#63; and privateLayout = &#63; and friendlyURL = &#63;.
3904             *
3905             * <p>
3906             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link LayoutFriendlyURLModelImpl}. 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.
3907             * </p>
3908             *
3909             * @param groupId the group ID
3910             * @param privateLayout the private layout
3911             * @param friendlyURL the friendly u r l
3912             * @param start the lower bound of the range of layout friendly u r ls
3913             * @param end the upper bound of the range of layout friendly u r ls (not inclusive)
3914             * @return the range of matching layout friendly u r ls
3915             */
3916            @Override
3917            public List<LayoutFriendlyURL> findByG_P_F(long groupId,
3918                    boolean privateLayout, String friendlyURL, int start, int end) {
3919                    return findByG_P_F(groupId, privateLayout, friendlyURL, start, end, null);
3920            }
3921    
3922            /**
3923             * Returns an ordered range of all the layout friendly u r ls where groupId = &#63; and privateLayout = &#63; and friendlyURL = &#63;.
3924             *
3925             * <p>
3926             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link LayoutFriendlyURLModelImpl}. 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.
3927             * </p>
3928             *
3929             * @param groupId the group ID
3930             * @param privateLayout the private layout
3931             * @param friendlyURL the friendly u r l
3932             * @param start the lower bound of the range of layout friendly u r ls
3933             * @param end the upper bound of the range of layout friendly u r ls (not inclusive)
3934             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3935             * @return the ordered range of matching layout friendly u r ls
3936             */
3937            @Override
3938            public List<LayoutFriendlyURL> findByG_P_F(long groupId,
3939                    boolean privateLayout, String friendlyURL, int start, int end,
3940                    OrderByComparator<LayoutFriendlyURL> orderByComparator) {
3941                    return findByG_P_F(groupId, privateLayout, friendlyURL, start, end,
3942                            orderByComparator, true);
3943            }
3944    
3945            /**
3946             * Returns an ordered range of all the layout friendly u r ls where groupId = &#63; and privateLayout = &#63; and friendlyURL = &#63;.
3947             *
3948             * <p>
3949             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link LayoutFriendlyURLModelImpl}. 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.
3950             * </p>
3951             *
3952             * @param groupId the group ID
3953             * @param privateLayout the private layout
3954             * @param friendlyURL the friendly u r l
3955             * @param start the lower bound of the range of layout friendly u r ls
3956             * @param end the upper bound of the range of layout friendly u r ls (not inclusive)
3957             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3958             * @param retrieveFromCache whether to retrieve from the finder cache
3959             * @return the ordered range of matching layout friendly u r ls
3960             */
3961            @Override
3962            public List<LayoutFriendlyURL> findByG_P_F(long groupId,
3963                    boolean privateLayout, String friendlyURL, int start, int end,
3964                    OrderByComparator<LayoutFriendlyURL> orderByComparator,
3965                    boolean retrieveFromCache) {
3966                    boolean pagination = true;
3967                    FinderPath finderPath = null;
3968                    Object[] finderArgs = null;
3969    
3970                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3971                                    (orderByComparator == null)) {
3972                            pagination = false;
3973                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_F;
3974                            finderArgs = new Object[] { groupId, privateLayout, friendlyURL };
3975                    }
3976                    else {
3977                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_F;
3978                            finderArgs = new Object[] {
3979                                            groupId, privateLayout, friendlyURL,
3980                                            
3981                                            start, end, orderByComparator
3982                                    };
3983                    }
3984    
3985                    List<LayoutFriendlyURL> list = null;
3986    
3987                    if (retrieveFromCache) {
3988                            list = (List<LayoutFriendlyURL>)finderCache.getResult(finderPath,
3989                                            finderArgs, this);
3990    
3991                            if ((list != null) && !list.isEmpty()) {
3992                                    for (LayoutFriendlyURL layoutFriendlyURL : list) {
3993                                            if ((groupId != layoutFriendlyURL.getGroupId()) ||
3994                                                            (privateLayout != layoutFriendlyURL.getPrivateLayout()) ||
3995                                                            !Objects.equals(friendlyURL,
3996                                                                    layoutFriendlyURL.getFriendlyURL())) {
3997                                                    list = null;
3998    
3999                                                    break;
4000                                            }
4001                                    }
4002                            }
4003                    }
4004    
4005                    if (list == null) {
4006                            StringBundler query = null;
4007    
4008                            if (orderByComparator != null) {
4009                                    query = new StringBundler(5 +
4010                                                    (orderByComparator.getOrderByFields().length * 2));
4011                            }
4012                            else {
4013                                    query = new StringBundler(5);
4014                            }
4015    
4016                            query.append(_SQL_SELECT_LAYOUTFRIENDLYURL_WHERE);
4017    
4018                            query.append(_FINDER_COLUMN_G_P_F_GROUPID_2);
4019    
4020                            query.append(_FINDER_COLUMN_G_P_F_PRIVATELAYOUT_2);
4021    
4022                            boolean bindFriendlyURL = false;
4023    
4024                            if (friendlyURL == null) {
4025                                    query.append(_FINDER_COLUMN_G_P_F_FRIENDLYURL_1);
4026                            }
4027                            else if (friendlyURL.equals(StringPool.BLANK)) {
4028                                    query.append(_FINDER_COLUMN_G_P_F_FRIENDLYURL_3);
4029                            }
4030                            else {
4031                                    bindFriendlyURL = true;
4032    
4033                                    query.append(_FINDER_COLUMN_G_P_F_FRIENDLYURL_2);
4034                            }
4035    
4036                            if (orderByComparator != null) {
4037                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4038                                            orderByComparator);
4039                            }
4040                            else
4041                             if (pagination) {
4042                                    query.append(LayoutFriendlyURLModelImpl.ORDER_BY_JPQL);
4043                            }
4044    
4045                            String sql = query.toString();
4046    
4047                            Session session = null;
4048    
4049                            try {
4050                                    session = openSession();
4051    
4052                                    Query q = session.createQuery(sql);
4053    
4054                                    QueryPos qPos = QueryPos.getInstance(q);
4055    
4056                                    qPos.add(groupId);
4057    
4058                                    qPos.add(privateLayout);
4059    
4060                                    if (bindFriendlyURL) {
4061                                            qPos.add(friendlyURL);
4062                                    }
4063    
4064                                    if (!pagination) {
4065                                            list = (List<LayoutFriendlyURL>)QueryUtil.list(q,
4066                                                            getDialect(), start, end, false);
4067    
4068                                            Collections.sort(list);
4069    
4070                                            list = Collections.unmodifiableList(list);
4071                                    }
4072                                    else {
4073                                            list = (List<LayoutFriendlyURL>)QueryUtil.list(q,
4074                                                            getDialect(), start, end);
4075                                    }
4076    
4077                                    cacheResult(list);
4078    
4079                                    finderCache.putResult(finderPath, finderArgs, list);
4080                            }
4081                            catch (Exception e) {
4082                                    finderCache.removeResult(finderPath, finderArgs);
4083    
4084                                    throw processException(e);
4085                            }
4086                            finally {
4087                                    closeSession(session);
4088                            }
4089                    }
4090    
4091                    return list;
4092            }
4093    
4094            /**
4095             * Returns the first layout friendly u r l in the ordered set where groupId = &#63; and privateLayout = &#63; and friendlyURL = &#63;.
4096             *
4097             * @param groupId the group ID
4098             * @param privateLayout the private layout
4099             * @param friendlyURL the friendly u r l
4100             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4101             * @return the first matching layout friendly u r l
4102             * @throws NoSuchLayoutFriendlyURLException if a matching layout friendly u r l could not be found
4103             */
4104            @Override
4105            public LayoutFriendlyURL findByG_P_F_First(long groupId,
4106                    boolean privateLayout, String friendlyURL,
4107                    OrderByComparator<LayoutFriendlyURL> orderByComparator)
4108                    throws NoSuchLayoutFriendlyURLException {
4109                    LayoutFriendlyURL layoutFriendlyURL = fetchByG_P_F_First(groupId,
4110                                    privateLayout, friendlyURL, orderByComparator);
4111    
4112                    if (layoutFriendlyURL != null) {
4113                            return layoutFriendlyURL;
4114                    }
4115    
4116                    StringBundler msg = new StringBundler(8);
4117    
4118                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4119    
4120                    msg.append("groupId=");
4121                    msg.append(groupId);
4122    
4123                    msg.append(", privateLayout=");
4124                    msg.append(privateLayout);
4125    
4126                    msg.append(", friendlyURL=");
4127                    msg.append(friendlyURL);
4128    
4129                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4130    
4131                    throw new NoSuchLayoutFriendlyURLException(msg.toString());
4132            }
4133    
4134            /**
4135             * Returns the first layout friendly u r l in the ordered set where groupId = &#63; and privateLayout = &#63; and friendlyURL = &#63;.
4136             *
4137             * @param groupId the group ID
4138             * @param privateLayout the private layout
4139             * @param friendlyURL the friendly u r l
4140             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4141             * @return the first matching layout friendly u r l, or <code>null</code> if a matching layout friendly u r l could not be found
4142             */
4143            @Override
4144            public LayoutFriendlyURL fetchByG_P_F_First(long groupId,
4145                    boolean privateLayout, String friendlyURL,
4146                    OrderByComparator<LayoutFriendlyURL> orderByComparator) {
4147                    List<LayoutFriendlyURL> list = findByG_P_F(groupId, privateLayout,
4148                                    friendlyURL, 0, 1, orderByComparator);
4149    
4150                    if (!list.isEmpty()) {
4151                            return list.get(0);
4152                    }
4153    
4154                    return null;
4155            }
4156    
4157            /**
4158             * Returns the last layout friendly u r l in the ordered set where groupId = &#63; and privateLayout = &#63; and friendlyURL = &#63;.
4159             *
4160             * @param groupId the group ID
4161             * @param privateLayout the private layout
4162             * @param friendlyURL the friendly u r l
4163             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4164             * @return the last matching layout friendly u r l
4165             * @throws NoSuchLayoutFriendlyURLException if a matching layout friendly u r l could not be found
4166             */
4167            @Override
4168            public LayoutFriendlyURL findByG_P_F_Last(long groupId,
4169                    boolean privateLayout, String friendlyURL,
4170                    OrderByComparator<LayoutFriendlyURL> orderByComparator)
4171                    throws NoSuchLayoutFriendlyURLException {
4172                    LayoutFriendlyURL layoutFriendlyURL = fetchByG_P_F_Last(groupId,
4173                                    privateLayout, friendlyURL, orderByComparator);
4174    
4175                    if (layoutFriendlyURL != null) {
4176                            return layoutFriendlyURL;
4177                    }
4178    
4179                    StringBundler msg = new StringBundler(8);
4180    
4181                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4182    
4183                    msg.append("groupId=");
4184                    msg.append(groupId);
4185    
4186                    msg.append(", privateLayout=");
4187                    msg.append(privateLayout);
4188    
4189                    msg.append(", friendlyURL=");
4190                    msg.append(friendlyURL);
4191    
4192                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4193    
4194                    throw new NoSuchLayoutFriendlyURLException(msg.toString());
4195            }
4196    
4197            /**
4198             * Returns the last layout friendly u r l in the ordered set where groupId = &#63; and privateLayout = &#63; and friendlyURL = &#63;.
4199             *
4200             * @param groupId the group ID
4201             * @param privateLayout the private layout
4202             * @param friendlyURL the friendly u r l
4203             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4204             * @return the last matching layout friendly u r l, or <code>null</code> if a matching layout friendly u r l could not be found
4205             */
4206            @Override
4207            public LayoutFriendlyURL fetchByG_P_F_Last(long groupId,
4208                    boolean privateLayout, String friendlyURL,
4209                    OrderByComparator<LayoutFriendlyURL> orderByComparator) {
4210                    int count = countByG_P_F(groupId, privateLayout, friendlyURL);
4211    
4212                    if (count == 0) {
4213                            return null;
4214                    }
4215    
4216                    List<LayoutFriendlyURL> list = findByG_P_F(groupId, privateLayout,
4217                                    friendlyURL, count - 1, count, orderByComparator);
4218    
4219                    if (!list.isEmpty()) {
4220                            return list.get(0);
4221                    }
4222    
4223                    return null;
4224            }
4225    
4226            /**
4227             * Returns the layout friendly u r ls before and after the current layout friendly u r l in the ordered set where groupId = &#63; and privateLayout = &#63; and friendlyURL = &#63;.
4228             *
4229             * @param layoutFriendlyURLId the primary key of the current layout friendly u r l
4230             * @param groupId the group ID
4231             * @param privateLayout the private layout
4232             * @param friendlyURL the friendly u r l
4233             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4234             * @return the previous, current, and next layout friendly u r l
4235             * @throws NoSuchLayoutFriendlyURLException if a layout friendly u r l with the primary key could not be found
4236             */
4237            @Override
4238            public LayoutFriendlyURL[] findByG_P_F_PrevAndNext(
4239                    long layoutFriendlyURLId, long groupId, boolean privateLayout,
4240                    String friendlyURL,
4241                    OrderByComparator<LayoutFriendlyURL> orderByComparator)
4242                    throws NoSuchLayoutFriendlyURLException {
4243                    LayoutFriendlyURL layoutFriendlyURL = findByPrimaryKey(layoutFriendlyURLId);
4244    
4245                    Session session = null;
4246    
4247                    try {
4248                            session = openSession();
4249    
4250                            LayoutFriendlyURL[] array = new LayoutFriendlyURLImpl[3];
4251    
4252                            array[0] = getByG_P_F_PrevAndNext(session, layoutFriendlyURL,
4253                                            groupId, privateLayout, friendlyURL, orderByComparator, true);
4254    
4255                            array[1] = layoutFriendlyURL;
4256    
4257                            array[2] = getByG_P_F_PrevAndNext(session, layoutFriendlyURL,
4258                                            groupId, privateLayout, friendlyURL, orderByComparator,
4259                                            false);
4260    
4261                            return array;
4262                    }
4263                    catch (Exception e) {
4264                            throw processException(e);
4265                    }
4266                    finally {
4267                            closeSession(session);
4268                    }
4269            }
4270    
4271            protected LayoutFriendlyURL getByG_P_F_PrevAndNext(Session session,
4272                    LayoutFriendlyURL layoutFriendlyURL, long groupId,
4273                    boolean privateLayout, String friendlyURL,
4274                    OrderByComparator<LayoutFriendlyURL> orderByComparator, boolean previous) {
4275                    StringBundler query = null;
4276    
4277                    if (orderByComparator != null) {
4278                            query = new StringBundler(6 +
4279                                            (orderByComparator.getOrderByConditionFields().length * 3) +
4280                                            (orderByComparator.getOrderByFields().length * 3));
4281                    }
4282                    else {
4283                            query = new StringBundler(5);
4284                    }
4285    
4286                    query.append(_SQL_SELECT_LAYOUTFRIENDLYURL_WHERE);
4287    
4288                    query.append(_FINDER_COLUMN_G_P_F_GROUPID_2);
4289    
4290                    query.append(_FINDER_COLUMN_G_P_F_PRIVATELAYOUT_2);
4291    
4292                    boolean bindFriendlyURL = false;
4293    
4294                    if (friendlyURL == null) {
4295                            query.append(_FINDER_COLUMN_G_P_F_FRIENDLYURL_1);
4296                    }
4297                    else if (friendlyURL.equals(StringPool.BLANK)) {
4298                            query.append(_FINDER_COLUMN_G_P_F_FRIENDLYURL_3);
4299                    }
4300                    else {
4301                            bindFriendlyURL = true;
4302    
4303                            query.append(_FINDER_COLUMN_G_P_F_FRIENDLYURL_2);
4304                    }
4305    
4306                    if (orderByComparator != null) {
4307                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4308    
4309                            if (orderByConditionFields.length > 0) {
4310                                    query.append(WHERE_AND);
4311                            }
4312    
4313                            for (int i = 0; i < orderByConditionFields.length; i++) {
4314                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4315                                    query.append(orderByConditionFields[i]);
4316    
4317                                    if ((i + 1) < orderByConditionFields.length) {
4318                                            if (orderByComparator.isAscending() ^ previous) {
4319                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4320                                            }
4321                                            else {
4322                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4323                                            }
4324                                    }
4325                                    else {
4326                                            if (orderByComparator.isAscending() ^ previous) {
4327                                                    query.append(WHERE_GREATER_THAN);
4328                                            }
4329                                            else {
4330                                                    query.append(WHERE_LESSER_THAN);
4331                                            }
4332                                    }
4333                            }
4334    
4335                            query.append(ORDER_BY_CLAUSE);
4336    
4337                            String[] orderByFields = orderByComparator.getOrderByFields();
4338    
4339                            for (int i = 0; i < orderByFields.length; i++) {
4340                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4341                                    query.append(orderByFields[i]);
4342    
4343                                    if ((i + 1) < orderByFields.length) {
4344                                            if (orderByComparator.isAscending() ^ previous) {
4345                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4346                                            }
4347                                            else {
4348                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4349                                            }
4350                                    }
4351                                    else {
4352                                            if (orderByComparator.isAscending() ^ previous) {
4353                                                    query.append(ORDER_BY_ASC);
4354                                            }
4355                                            else {
4356                                                    query.append(ORDER_BY_DESC);
4357                                            }
4358                                    }
4359                            }
4360                    }
4361                    else {
4362                            query.append(LayoutFriendlyURLModelImpl.ORDER_BY_JPQL);
4363                    }
4364    
4365                    String sql = query.toString();
4366    
4367                    Query q = session.createQuery(sql);
4368    
4369                    q.setFirstResult(0);
4370                    q.setMaxResults(2);
4371    
4372                    QueryPos qPos = QueryPos.getInstance(q);
4373    
4374                    qPos.add(groupId);
4375    
4376                    qPos.add(privateLayout);
4377    
4378                    if (bindFriendlyURL) {
4379                            qPos.add(friendlyURL);
4380                    }
4381    
4382                    if (orderByComparator != null) {
4383                            Object[] values = orderByComparator.getOrderByConditionValues(layoutFriendlyURL);
4384    
4385                            for (Object value : values) {
4386                                    qPos.add(value);
4387                            }
4388                    }
4389    
4390                    List<LayoutFriendlyURL> list = q.list();
4391    
4392                    if (list.size() == 2) {
4393                            return list.get(1);
4394                    }
4395                    else {
4396                            return null;
4397                    }
4398            }
4399    
4400            /**
4401             * Removes all the layout friendly u r ls where groupId = &#63; and privateLayout = &#63; and friendlyURL = &#63; from the database.
4402             *
4403             * @param groupId the group ID
4404             * @param privateLayout the private layout
4405             * @param friendlyURL the friendly u r l
4406             */
4407            @Override
4408            public void removeByG_P_F(long groupId, boolean privateLayout,
4409                    String friendlyURL) {
4410                    for (LayoutFriendlyURL layoutFriendlyURL : findByG_P_F(groupId,
4411                                    privateLayout, friendlyURL, QueryUtil.ALL_POS,
4412                                    QueryUtil.ALL_POS, null)) {
4413                            remove(layoutFriendlyURL);
4414                    }
4415            }
4416    
4417            /**
4418             * Returns the number of layout friendly u r ls where groupId = &#63; and privateLayout = &#63; and friendlyURL = &#63;.
4419             *
4420             * @param groupId the group ID
4421             * @param privateLayout the private layout
4422             * @param friendlyURL the friendly u r l
4423             * @return the number of matching layout friendly u r ls
4424             */
4425            @Override
4426            public int countByG_P_F(long groupId, boolean privateLayout,
4427                    String friendlyURL) {
4428                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_P_F;
4429    
4430                    Object[] finderArgs = new Object[] { groupId, privateLayout, friendlyURL };
4431    
4432                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
4433    
4434                    if (count == null) {
4435                            StringBundler query = new StringBundler(4);
4436    
4437                            query.append(_SQL_COUNT_LAYOUTFRIENDLYURL_WHERE);
4438    
4439                            query.append(_FINDER_COLUMN_G_P_F_GROUPID_2);
4440    
4441                            query.append(_FINDER_COLUMN_G_P_F_PRIVATELAYOUT_2);
4442    
4443                            boolean bindFriendlyURL = false;
4444    
4445                            if (friendlyURL == null) {
4446                                    query.append(_FINDER_COLUMN_G_P_F_FRIENDLYURL_1);
4447                            }
4448                            else if (friendlyURL.equals(StringPool.BLANK)) {
4449                                    query.append(_FINDER_COLUMN_G_P_F_FRIENDLYURL_3);
4450                            }
4451                            else {
4452                                    bindFriendlyURL = true;
4453    
4454                                    query.append(_FINDER_COLUMN_G_P_F_FRIENDLYURL_2);
4455                            }
4456    
4457                            String sql = query.toString();
4458    
4459                            Session session = null;
4460    
4461                            try {
4462                                    session = openSession();
4463    
4464                                    Query q = session.createQuery(sql);
4465    
4466                                    QueryPos qPos = QueryPos.getInstance(q);
4467    
4468                                    qPos.add(groupId);
4469    
4470                                    qPos.add(privateLayout);
4471    
4472                                    if (bindFriendlyURL) {
4473                                            qPos.add(friendlyURL);
4474                                    }
4475    
4476                                    count = (Long)q.uniqueResult();
4477    
4478                                    finderCache.putResult(finderPath, finderArgs, count);
4479                            }
4480                            catch (Exception e) {
4481                                    finderCache.removeResult(finderPath, finderArgs);
4482    
4483                                    throw processException(e);
4484                            }
4485                            finally {
4486                                    closeSession(session);
4487                            }
4488                    }
4489    
4490                    return count.intValue();
4491            }
4492    
4493            private static final String _FINDER_COLUMN_G_P_F_GROUPID_2 = "layoutFriendlyURL.groupId = ? AND ";
4494            private static final String _FINDER_COLUMN_G_P_F_PRIVATELAYOUT_2 = "layoutFriendlyURL.privateLayout = ? AND ";
4495            private static final String _FINDER_COLUMN_G_P_F_FRIENDLYURL_1 = "layoutFriendlyURL.friendlyURL IS NULL";
4496            private static final String _FINDER_COLUMN_G_P_F_FRIENDLYURL_2 = "layoutFriendlyURL.friendlyURL = ?";
4497            private static final String _FINDER_COLUMN_G_P_F_FRIENDLYURL_3 = "(layoutFriendlyURL.friendlyURL IS NULL OR layoutFriendlyURL.friendlyURL = '')";
4498            public static final FinderPath FINDER_PATH_FETCH_BY_G_P_F_L = new FinderPath(LayoutFriendlyURLModelImpl.ENTITY_CACHE_ENABLED,
4499                            LayoutFriendlyURLModelImpl.FINDER_CACHE_ENABLED,
4500                            LayoutFriendlyURLImpl.class, FINDER_CLASS_NAME_ENTITY,
4501                            "fetchByG_P_F_L",
4502                            new String[] {
4503                                    Long.class.getName(), Boolean.class.getName(),
4504                                    String.class.getName(), String.class.getName()
4505                            },
4506                            LayoutFriendlyURLModelImpl.GROUPID_COLUMN_BITMASK |
4507                            LayoutFriendlyURLModelImpl.PRIVATELAYOUT_COLUMN_BITMASK |
4508                            LayoutFriendlyURLModelImpl.FRIENDLYURL_COLUMN_BITMASK |
4509                            LayoutFriendlyURLModelImpl.LANGUAGEID_COLUMN_BITMASK);
4510            public static final FinderPath FINDER_PATH_COUNT_BY_G_P_F_L = new FinderPath(LayoutFriendlyURLModelImpl.ENTITY_CACHE_ENABLED,
4511                            LayoutFriendlyURLModelImpl.FINDER_CACHE_ENABLED, Long.class,
4512                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P_F_L",
4513                            new String[] {
4514                                    Long.class.getName(), Boolean.class.getName(),
4515                                    String.class.getName(), String.class.getName()
4516                            });
4517    
4518            /**
4519             * Returns the layout friendly u r l where groupId = &#63; and privateLayout = &#63; and friendlyURL = &#63; and languageId = &#63; or throws a {@link NoSuchLayoutFriendlyURLException} if it could not be found.
4520             *
4521             * @param groupId the group ID
4522             * @param privateLayout the private layout
4523             * @param friendlyURL the friendly u r l
4524             * @param languageId the language ID
4525             * @return the matching layout friendly u r l
4526             * @throws NoSuchLayoutFriendlyURLException if a matching layout friendly u r l could not be found
4527             */
4528            @Override
4529            public LayoutFriendlyURL findByG_P_F_L(long groupId, boolean privateLayout,
4530                    String friendlyURL, String languageId)
4531                    throws NoSuchLayoutFriendlyURLException {
4532                    LayoutFriendlyURL layoutFriendlyURL = fetchByG_P_F_L(groupId,
4533                                    privateLayout, friendlyURL, languageId);
4534    
4535                    if (layoutFriendlyURL == null) {
4536                            StringBundler msg = new StringBundler(10);
4537    
4538                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4539    
4540                            msg.append("groupId=");
4541                            msg.append(groupId);
4542    
4543                            msg.append(", privateLayout=");
4544                            msg.append(privateLayout);
4545    
4546                            msg.append(", friendlyURL=");
4547                            msg.append(friendlyURL);
4548    
4549                            msg.append(", languageId=");
4550                            msg.append(languageId);
4551    
4552                            msg.append(StringPool.CLOSE_CURLY_BRACE);
4553    
4554                            if (_log.isDebugEnabled()) {
4555                                    _log.debug(msg.toString());
4556                            }
4557    
4558                            throw new NoSuchLayoutFriendlyURLException(msg.toString());
4559                    }
4560    
4561                    return layoutFriendlyURL;
4562            }
4563    
4564            /**
4565             * Returns the layout friendly u r l where groupId = &#63; and privateLayout = &#63; and friendlyURL = &#63; and languageId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
4566             *
4567             * @param groupId the group ID
4568             * @param privateLayout the private layout
4569             * @param friendlyURL the friendly u r l
4570             * @param languageId the language ID
4571             * @return the matching layout friendly u r l, or <code>null</code> if a matching layout friendly u r l could not be found
4572             */
4573            @Override
4574            public LayoutFriendlyURL fetchByG_P_F_L(long groupId,
4575                    boolean privateLayout, String friendlyURL, String languageId) {
4576                    return fetchByG_P_F_L(groupId, privateLayout, friendlyURL, languageId,
4577                            true);
4578            }
4579    
4580            /**
4581             * Returns the layout friendly u r l where groupId = &#63; and privateLayout = &#63; and friendlyURL = &#63; and languageId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
4582             *
4583             * @param groupId the group ID
4584             * @param privateLayout the private layout
4585             * @param friendlyURL the friendly u r l
4586             * @param languageId the language ID
4587             * @param retrieveFromCache whether to retrieve from the finder cache
4588             * @return the matching layout friendly u r l, or <code>null</code> if a matching layout friendly u r l could not be found
4589             */
4590            @Override
4591            public LayoutFriendlyURL fetchByG_P_F_L(long groupId,
4592                    boolean privateLayout, String friendlyURL, String languageId,
4593                    boolean retrieveFromCache) {
4594                    Object[] finderArgs = new Object[] {
4595                                    groupId, privateLayout, friendlyURL, languageId
4596                            };
4597    
4598                    Object result = null;
4599    
4600                    if (retrieveFromCache) {
4601                            result = finderCache.getResult(FINDER_PATH_FETCH_BY_G_P_F_L,
4602                                            finderArgs, this);
4603                    }
4604    
4605                    if (result instanceof LayoutFriendlyURL) {
4606                            LayoutFriendlyURL layoutFriendlyURL = (LayoutFriendlyURL)result;
4607    
4608                            if ((groupId != layoutFriendlyURL.getGroupId()) ||
4609                                            (privateLayout != layoutFriendlyURL.getPrivateLayout()) ||
4610                                            !Objects.equals(friendlyURL,
4611                                                    layoutFriendlyURL.getFriendlyURL()) ||
4612                                            !Objects.equals(languageId,
4613                                                    layoutFriendlyURL.getLanguageId())) {
4614                                    result = null;
4615                            }
4616                    }
4617    
4618                    if (result == null) {
4619                            StringBundler query = new StringBundler(6);
4620    
4621                            query.append(_SQL_SELECT_LAYOUTFRIENDLYURL_WHERE);
4622    
4623                            query.append(_FINDER_COLUMN_G_P_F_L_GROUPID_2);
4624    
4625                            query.append(_FINDER_COLUMN_G_P_F_L_PRIVATELAYOUT_2);
4626    
4627                            boolean bindFriendlyURL = false;
4628    
4629                            if (friendlyURL == null) {
4630                                    query.append(_FINDER_COLUMN_G_P_F_L_FRIENDLYURL_1);
4631                            }
4632                            else if (friendlyURL.equals(StringPool.BLANK)) {
4633                                    query.append(_FINDER_COLUMN_G_P_F_L_FRIENDLYURL_3);
4634                            }
4635                            else {
4636                                    bindFriendlyURL = true;
4637    
4638                                    query.append(_FINDER_COLUMN_G_P_F_L_FRIENDLYURL_2);
4639                            }
4640    
4641                            boolean bindLanguageId = false;
4642    
4643                            if (languageId == null) {
4644                                    query.append(_FINDER_COLUMN_G_P_F_L_LANGUAGEID_1);
4645                            }
4646                            else if (languageId.equals(StringPool.BLANK)) {
4647                                    query.append(_FINDER_COLUMN_G_P_F_L_LANGUAGEID_3);
4648                            }
4649                            else {
4650                                    bindLanguageId = true;
4651    
4652                                    query.append(_FINDER_COLUMN_G_P_F_L_LANGUAGEID_2);
4653                            }
4654    
4655                            String sql = query.toString();
4656    
4657                            Session session = null;
4658    
4659                            try {
4660                                    session = openSession();
4661    
4662                                    Query q = session.createQuery(sql);
4663    
4664                                    QueryPos qPos = QueryPos.getInstance(q);
4665    
4666                                    qPos.add(groupId);
4667    
4668                                    qPos.add(privateLayout);
4669    
4670                                    if (bindFriendlyURL) {
4671                                            qPos.add(friendlyURL);
4672                                    }
4673    
4674                                    if (bindLanguageId) {
4675                                            qPos.add(languageId);
4676                                    }
4677    
4678                                    List<LayoutFriendlyURL> list = q.list();
4679    
4680                                    if (list.isEmpty()) {
4681                                            finderCache.putResult(FINDER_PATH_FETCH_BY_G_P_F_L,
4682                                                    finderArgs, list);
4683                                    }
4684                                    else {
4685                                            LayoutFriendlyURL layoutFriendlyURL = list.get(0);
4686    
4687                                            result = layoutFriendlyURL;
4688    
4689                                            cacheResult(layoutFriendlyURL);
4690    
4691                                            if ((layoutFriendlyURL.getGroupId() != groupId) ||
4692                                                            (layoutFriendlyURL.getPrivateLayout() != privateLayout) ||
4693                                                            (layoutFriendlyURL.getFriendlyURL() == null) ||
4694                                                            !layoutFriendlyURL.getFriendlyURL()
4695                                                                                                      .equals(friendlyURL) ||
4696                                                            (layoutFriendlyURL.getLanguageId() == null) ||
4697                                                            !layoutFriendlyURL.getLanguageId().equals(languageId)) {
4698                                                    finderCache.putResult(FINDER_PATH_FETCH_BY_G_P_F_L,
4699                                                            finderArgs, layoutFriendlyURL);
4700                                            }
4701                                    }
4702                            }
4703                            catch (Exception e) {
4704                                    finderCache.removeResult(FINDER_PATH_FETCH_BY_G_P_F_L,
4705                                            finderArgs);
4706    
4707                                    throw processException(e);
4708                            }
4709                            finally {
4710                                    closeSession(session);
4711                            }
4712                    }
4713    
4714                    if (result instanceof List<?>) {
4715                            return null;
4716                    }
4717                    else {
4718                            return (LayoutFriendlyURL)result;
4719                    }
4720            }
4721    
4722            /**
4723             * Removes the layout friendly u r l where groupId = &#63; and privateLayout = &#63; and friendlyURL = &#63; and languageId = &#63; from the database.
4724             *
4725             * @param groupId the group ID
4726             * @param privateLayout the private layout
4727             * @param friendlyURL the friendly u r l
4728             * @param languageId the language ID
4729             * @return the layout friendly u r l that was removed
4730             */
4731            @Override
4732            public LayoutFriendlyURL removeByG_P_F_L(long groupId,
4733                    boolean privateLayout, String friendlyURL, String languageId)
4734                    throws NoSuchLayoutFriendlyURLException {
4735                    LayoutFriendlyURL layoutFriendlyURL = findByG_P_F_L(groupId,
4736                                    privateLayout, friendlyURL, languageId);
4737    
4738                    return remove(layoutFriendlyURL);
4739            }
4740    
4741            /**
4742             * Returns the number of layout friendly u r ls where groupId = &#63; and privateLayout = &#63; and friendlyURL = &#63; and languageId = &#63;.
4743             *
4744             * @param groupId the group ID
4745             * @param privateLayout the private layout
4746             * @param friendlyURL the friendly u r l
4747             * @param languageId the language ID
4748             * @return the number of matching layout friendly u r ls
4749             */
4750            @Override
4751            public int countByG_P_F_L(long groupId, boolean privateLayout,
4752                    String friendlyURL, String languageId) {
4753                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_P_F_L;
4754    
4755                    Object[] finderArgs = new Object[] {
4756                                    groupId, privateLayout, friendlyURL, languageId
4757                            };
4758    
4759                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
4760    
4761                    if (count == null) {
4762                            StringBundler query = new StringBundler(5);
4763    
4764                            query.append(_SQL_COUNT_LAYOUTFRIENDLYURL_WHERE);
4765    
4766                            query.append(_FINDER_COLUMN_G_P_F_L_GROUPID_2);
4767    
4768                            query.append(_FINDER_COLUMN_G_P_F_L_PRIVATELAYOUT_2);
4769    
4770                            boolean bindFriendlyURL = false;
4771    
4772                            if (friendlyURL == null) {
4773                                    query.append(_FINDER_COLUMN_G_P_F_L_FRIENDLYURL_1);
4774                            }
4775                            else if (friendlyURL.equals(StringPool.BLANK)) {
4776                                    query.append(_FINDER_COLUMN_G_P_F_L_FRIENDLYURL_3);
4777                            }
4778                            else {
4779                                    bindFriendlyURL = true;
4780    
4781                                    query.append(_FINDER_COLUMN_G_P_F_L_FRIENDLYURL_2);
4782                            }
4783    
4784                            boolean bindLanguageId = false;
4785    
4786                            if (languageId == null) {
4787                                    query.append(_FINDER_COLUMN_G_P_F_L_LANGUAGEID_1);
4788                            }
4789                            else if (languageId.equals(StringPool.BLANK)) {
4790                                    query.append(_FINDER_COLUMN_G_P_F_L_LANGUAGEID_3);
4791                            }
4792                            else {
4793                                    bindLanguageId = true;
4794    
4795                                    query.append(_FINDER_COLUMN_G_P_F_L_LANGUAGEID_2);
4796                            }
4797    
4798                            String sql = query.toString();
4799    
4800                            Session session = null;
4801    
4802                            try {
4803                                    session = openSession();
4804    
4805                                    Query q = session.createQuery(sql);
4806    
4807                                    QueryPos qPos = QueryPos.getInstance(q);
4808    
4809                                    qPos.add(groupId);
4810    
4811                                    qPos.add(privateLayout);
4812    
4813                                    if (bindFriendlyURL) {
4814                                            qPos.add(friendlyURL);
4815                                    }
4816    
4817                                    if (bindLanguageId) {
4818                                            qPos.add(languageId);
4819                                    }
4820    
4821                                    count = (Long)q.uniqueResult();
4822    
4823                                    finderCache.putResult(finderPath, finderArgs, count);
4824                            }
4825                            catch (Exception e) {
4826                                    finderCache.removeResult(finderPath, finderArgs);
4827    
4828                                    throw processException(e);
4829                            }
4830                            finally {
4831                                    closeSession(session);
4832                            }
4833                    }
4834    
4835                    return count.intValue();
4836            }
4837    
4838            private static final String _FINDER_COLUMN_G_P_F_L_GROUPID_2 = "layoutFriendlyURL.groupId = ? AND ";
4839            private static final String _FINDER_COLUMN_G_P_F_L_PRIVATELAYOUT_2 = "layoutFriendlyURL.privateLayout = ? AND ";
4840            private static final String _FINDER_COLUMN_G_P_F_L_FRIENDLYURL_1 = "layoutFriendlyURL.friendlyURL IS NULL AND ";
4841            private static final String _FINDER_COLUMN_G_P_F_L_FRIENDLYURL_2 = "layoutFriendlyURL.friendlyURL = ? AND ";
4842            private static final String _FINDER_COLUMN_G_P_F_L_FRIENDLYURL_3 = "(layoutFriendlyURL.friendlyURL IS NULL OR layoutFriendlyURL.friendlyURL = '') AND ";
4843            private static final String _FINDER_COLUMN_G_P_F_L_LANGUAGEID_1 = "layoutFriendlyURL.languageId IS NULL";
4844            private static final String _FINDER_COLUMN_G_P_F_L_LANGUAGEID_2 = "layoutFriendlyURL.languageId = ?";
4845            private static final String _FINDER_COLUMN_G_P_F_L_LANGUAGEID_3 = "(layoutFriendlyURL.languageId IS NULL OR layoutFriendlyURL.languageId = '')";
4846    
4847            public LayoutFriendlyURLPersistenceImpl() {
4848                    setModelClass(LayoutFriendlyURL.class);
4849            }
4850    
4851            /**
4852             * Caches the layout friendly u r l in the entity cache if it is enabled.
4853             *
4854             * @param layoutFriendlyURL the layout friendly u r l
4855             */
4856            @Override
4857            public void cacheResult(LayoutFriendlyURL layoutFriendlyURL) {
4858                    entityCache.putResult(LayoutFriendlyURLModelImpl.ENTITY_CACHE_ENABLED,
4859                            LayoutFriendlyURLImpl.class, layoutFriendlyURL.getPrimaryKey(),
4860                            layoutFriendlyURL);
4861    
4862                    finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G,
4863                            new Object[] {
4864                                    layoutFriendlyURL.getUuid(), layoutFriendlyURL.getGroupId()
4865                            }, layoutFriendlyURL);
4866    
4867                    finderCache.putResult(FINDER_PATH_FETCH_BY_P_L,
4868                            new Object[] {
4869                                    layoutFriendlyURL.getPlid(), layoutFriendlyURL.getLanguageId()
4870                            }, layoutFriendlyURL);
4871    
4872                    finderCache.putResult(FINDER_PATH_FETCH_BY_G_P_F_L,
4873                            new Object[] {
4874                                    layoutFriendlyURL.getGroupId(),
4875                                    layoutFriendlyURL.getPrivateLayout(),
4876                                    layoutFriendlyURL.getFriendlyURL(),
4877                                    layoutFriendlyURL.getLanguageId()
4878                            }, layoutFriendlyURL);
4879    
4880                    layoutFriendlyURL.resetOriginalValues();
4881            }
4882    
4883            /**
4884             * Caches the layout friendly u r ls in the entity cache if it is enabled.
4885             *
4886             * @param layoutFriendlyURLs the layout friendly u r ls
4887             */
4888            @Override
4889            public void cacheResult(List<LayoutFriendlyURL> layoutFriendlyURLs) {
4890                    for (LayoutFriendlyURL layoutFriendlyURL : layoutFriendlyURLs) {
4891                            if (entityCache.getResult(
4892                                                    LayoutFriendlyURLModelImpl.ENTITY_CACHE_ENABLED,
4893                                                    LayoutFriendlyURLImpl.class,
4894                                                    layoutFriendlyURL.getPrimaryKey()) == null) {
4895                                    cacheResult(layoutFriendlyURL);
4896                            }
4897                            else {
4898                                    layoutFriendlyURL.resetOriginalValues();
4899                            }
4900                    }
4901            }
4902    
4903            /**
4904             * Clears the cache for all layout friendly u r ls.
4905             *
4906             * <p>
4907             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
4908             * </p>
4909             */
4910            @Override
4911            public void clearCache() {
4912                    entityCache.clearCache(LayoutFriendlyURLImpl.class);
4913    
4914                    finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
4915                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4916                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4917            }
4918    
4919            /**
4920             * Clears the cache for the layout friendly u r l.
4921             *
4922             * <p>
4923             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
4924             * </p>
4925             */
4926            @Override
4927            public void clearCache(LayoutFriendlyURL layoutFriendlyURL) {
4928                    entityCache.removeResult(LayoutFriendlyURLModelImpl.ENTITY_CACHE_ENABLED,
4929                            LayoutFriendlyURLImpl.class, layoutFriendlyURL.getPrimaryKey());
4930    
4931                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4932                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4933    
4934                    clearUniqueFindersCache((LayoutFriendlyURLModelImpl)layoutFriendlyURL);
4935            }
4936    
4937            @Override
4938            public void clearCache(List<LayoutFriendlyURL> layoutFriendlyURLs) {
4939                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4940                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4941    
4942                    for (LayoutFriendlyURL layoutFriendlyURL : layoutFriendlyURLs) {
4943                            entityCache.removeResult(LayoutFriendlyURLModelImpl.ENTITY_CACHE_ENABLED,
4944                                    LayoutFriendlyURLImpl.class, layoutFriendlyURL.getPrimaryKey());
4945    
4946                            clearUniqueFindersCache((LayoutFriendlyURLModelImpl)layoutFriendlyURL);
4947                    }
4948            }
4949    
4950            protected void cacheUniqueFindersCache(
4951                    LayoutFriendlyURLModelImpl layoutFriendlyURLModelImpl, boolean isNew) {
4952                    if (isNew) {
4953                            Object[] args = new Object[] {
4954                                            layoutFriendlyURLModelImpl.getUuid(),
4955                                            layoutFriendlyURLModelImpl.getGroupId()
4956                                    };
4957    
4958                            finderCache.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
4959                                    Long.valueOf(1));
4960                            finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
4961                                    layoutFriendlyURLModelImpl);
4962    
4963                            args = new Object[] {
4964                                            layoutFriendlyURLModelImpl.getPlid(),
4965                                            layoutFriendlyURLModelImpl.getLanguageId()
4966                                    };
4967    
4968                            finderCache.putResult(FINDER_PATH_COUNT_BY_P_L, args,
4969                                    Long.valueOf(1));
4970                            finderCache.putResult(FINDER_PATH_FETCH_BY_P_L, args,
4971                                    layoutFriendlyURLModelImpl);
4972    
4973                            args = new Object[] {
4974                                            layoutFriendlyURLModelImpl.getGroupId(),
4975                                            layoutFriendlyURLModelImpl.getPrivateLayout(),
4976                                            layoutFriendlyURLModelImpl.getFriendlyURL(),
4977                                            layoutFriendlyURLModelImpl.getLanguageId()
4978                                    };
4979    
4980                            finderCache.putResult(FINDER_PATH_COUNT_BY_G_P_F_L, args,
4981                                    Long.valueOf(1));
4982                            finderCache.putResult(FINDER_PATH_FETCH_BY_G_P_F_L, args,
4983                                    layoutFriendlyURLModelImpl);
4984                    }
4985                    else {
4986                            if ((layoutFriendlyURLModelImpl.getColumnBitmask() &
4987                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
4988                                    Object[] args = new Object[] {
4989                                                    layoutFriendlyURLModelImpl.getUuid(),
4990                                                    layoutFriendlyURLModelImpl.getGroupId()
4991                                            };
4992    
4993                                    finderCache.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
4994                                            Long.valueOf(1));
4995                                    finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
4996                                            layoutFriendlyURLModelImpl);
4997                            }
4998    
4999                            if ((layoutFriendlyURLModelImpl.getColumnBitmask() &
5000                                            FINDER_PATH_FETCH_BY_P_L.getColumnBitmask()) != 0) {
5001                                    Object[] args = new Object[] {
5002                                                    layoutFriendlyURLModelImpl.getPlid(),
5003                                                    layoutFriendlyURLModelImpl.getLanguageId()
5004                                            };
5005    
5006                                    finderCache.putResult(FINDER_PATH_COUNT_BY_P_L, args,
5007                                            Long.valueOf(1));
5008                                    finderCache.putResult(FINDER_PATH_FETCH_BY_P_L, args,
5009                                            layoutFriendlyURLModelImpl);
5010                            }
5011    
5012                            if ((layoutFriendlyURLModelImpl.getColumnBitmask() &
5013                                            FINDER_PATH_FETCH_BY_G_P_F_L.getColumnBitmask()) != 0) {
5014                                    Object[] args = new Object[] {
5015                                                    layoutFriendlyURLModelImpl.getGroupId(),
5016                                                    layoutFriendlyURLModelImpl.getPrivateLayout(),
5017                                                    layoutFriendlyURLModelImpl.getFriendlyURL(),
5018                                                    layoutFriendlyURLModelImpl.getLanguageId()
5019                                            };
5020    
5021                                    finderCache.putResult(FINDER_PATH_COUNT_BY_G_P_F_L, args,
5022                                            Long.valueOf(1));
5023                                    finderCache.putResult(FINDER_PATH_FETCH_BY_G_P_F_L, args,
5024                                            layoutFriendlyURLModelImpl);
5025                            }
5026                    }
5027            }
5028    
5029            protected void clearUniqueFindersCache(
5030                    LayoutFriendlyURLModelImpl layoutFriendlyURLModelImpl) {
5031                    Object[] args = new Object[] {
5032                                    layoutFriendlyURLModelImpl.getUuid(),
5033                                    layoutFriendlyURLModelImpl.getGroupId()
5034                            };
5035    
5036                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
5037                    finderCache.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
5038    
5039                    if ((layoutFriendlyURLModelImpl.getColumnBitmask() &
5040                                    FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
5041                            args = new Object[] {
5042                                            layoutFriendlyURLModelImpl.getOriginalUuid(),
5043                                            layoutFriendlyURLModelImpl.getOriginalGroupId()
5044                                    };
5045    
5046                            finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
5047                            finderCache.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
5048                    }
5049    
5050                    args = new Object[] {
5051                                    layoutFriendlyURLModelImpl.getPlid(),
5052                                    layoutFriendlyURLModelImpl.getLanguageId()
5053                            };
5054    
5055                    finderCache.removeResult(FINDER_PATH_COUNT_BY_P_L, args);
5056                    finderCache.removeResult(FINDER_PATH_FETCH_BY_P_L, args);
5057    
5058                    if ((layoutFriendlyURLModelImpl.getColumnBitmask() &
5059                                    FINDER_PATH_FETCH_BY_P_L.getColumnBitmask()) != 0) {
5060                            args = new Object[] {
5061                                            layoutFriendlyURLModelImpl.getOriginalPlid(),
5062                                            layoutFriendlyURLModelImpl.getOriginalLanguageId()
5063                                    };
5064    
5065                            finderCache.removeResult(FINDER_PATH_COUNT_BY_P_L, args);
5066                            finderCache.removeResult(FINDER_PATH_FETCH_BY_P_L, args);
5067                    }
5068    
5069                    args = new Object[] {
5070                                    layoutFriendlyURLModelImpl.getGroupId(),
5071                                    layoutFriendlyURLModelImpl.getPrivateLayout(),
5072                                    layoutFriendlyURLModelImpl.getFriendlyURL(),
5073                                    layoutFriendlyURLModelImpl.getLanguageId()
5074                            };
5075    
5076                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_P_F_L, args);
5077                    finderCache.removeResult(FINDER_PATH_FETCH_BY_G_P_F_L, args);
5078    
5079                    if ((layoutFriendlyURLModelImpl.getColumnBitmask() &
5080                                    FINDER_PATH_FETCH_BY_G_P_F_L.getColumnBitmask()) != 0) {
5081                            args = new Object[] {
5082                                            layoutFriendlyURLModelImpl.getOriginalGroupId(),
5083                                            layoutFriendlyURLModelImpl.getOriginalPrivateLayout(),
5084                                            layoutFriendlyURLModelImpl.getOriginalFriendlyURL(),
5085                                            layoutFriendlyURLModelImpl.getOriginalLanguageId()
5086                                    };
5087    
5088                            finderCache.removeResult(FINDER_PATH_COUNT_BY_G_P_F_L, args);
5089                            finderCache.removeResult(FINDER_PATH_FETCH_BY_G_P_F_L, args);
5090                    }
5091            }
5092    
5093            /**
5094             * Creates a new layout friendly u r l with the primary key. Does not add the layout friendly u r l to the database.
5095             *
5096             * @param layoutFriendlyURLId the primary key for the new layout friendly u r l
5097             * @return the new layout friendly u r l
5098             */
5099            @Override
5100            public LayoutFriendlyURL create(long layoutFriendlyURLId) {
5101                    LayoutFriendlyURL layoutFriendlyURL = new LayoutFriendlyURLImpl();
5102    
5103                    layoutFriendlyURL.setNew(true);
5104                    layoutFriendlyURL.setPrimaryKey(layoutFriendlyURLId);
5105    
5106                    String uuid = PortalUUIDUtil.generate();
5107    
5108                    layoutFriendlyURL.setUuid(uuid);
5109    
5110                    layoutFriendlyURL.setCompanyId(companyProvider.getCompanyId());
5111    
5112                    return layoutFriendlyURL;
5113            }
5114    
5115            /**
5116             * Removes the layout friendly u r l with the primary key from the database. Also notifies the appropriate model listeners.
5117             *
5118             * @param layoutFriendlyURLId the primary key of the layout friendly u r l
5119             * @return the layout friendly u r l that was removed
5120             * @throws NoSuchLayoutFriendlyURLException if a layout friendly u r l with the primary key could not be found
5121             */
5122            @Override
5123            public LayoutFriendlyURL remove(long layoutFriendlyURLId)
5124                    throws NoSuchLayoutFriendlyURLException {
5125                    return remove((Serializable)layoutFriendlyURLId);
5126            }
5127    
5128            /**
5129             * Removes the layout friendly u r l with the primary key from the database. Also notifies the appropriate model listeners.
5130             *
5131             * @param primaryKey the primary key of the layout friendly u r l
5132             * @return the layout friendly u r l that was removed
5133             * @throws NoSuchLayoutFriendlyURLException if a layout friendly u r l with the primary key could not be found
5134             */
5135            @Override
5136            public LayoutFriendlyURL remove(Serializable primaryKey)
5137                    throws NoSuchLayoutFriendlyURLException {
5138                    Session session = null;
5139    
5140                    try {
5141                            session = openSession();
5142    
5143                            LayoutFriendlyURL layoutFriendlyURL = (LayoutFriendlyURL)session.get(LayoutFriendlyURLImpl.class,
5144                                            primaryKey);
5145    
5146                            if (layoutFriendlyURL == null) {
5147                                    if (_log.isDebugEnabled()) {
5148                                            _log.debug(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
5149                                    }
5150    
5151                                    throw new NoSuchLayoutFriendlyURLException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
5152                                            primaryKey);
5153                            }
5154    
5155                            return remove(layoutFriendlyURL);
5156                    }
5157                    catch (NoSuchLayoutFriendlyURLException nsee) {
5158                            throw nsee;
5159                    }
5160                    catch (Exception e) {
5161                            throw processException(e);
5162                    }
5163                    finally {
5164                            closeSession(session);
5165                    }
5166            }
5167    
5168            @Override
5169            protected LayoutFriendlyURL removeImpl(LayoutFriendlyURL layoutFriendlyURL) {
5170                    layoutFriendlyURL = toUnwrappedModel(layoutFriendlyURL);
5171    
5172                    Session session = null;
5173    
5174                    try {
5175                            session = openSession();
5176    
5177                            if (!session.contains(layoutFriendlyURL)) {
5178                                    layoutFriendlyURL = (LayoutFriendlyURL)session.get(LayoutFriendlyURLImpl.class,
5179                                                    layoutFriendlyURL.getPrimaryKeyObj());
5180                            }
5181    
5182                            if (layoutFriendlyURL != null) {
5183                                    session.delete(layoutFriendlyURL);
5184                            }
5185                    }
5186                    catch (Exception e) {
5187                            throw processException(e);
5188                    }
5189                    finally {
5190                            closeSession(session);
5191                    }
5192    
5193                    if (layoutFriendlyURL != null) {
5194                            clearCache(layoutFriendlyURL);
5195                    }
5196    
5197                    return layoutFriendlyURL;
5198            }
5199    
5200            @Override
5201            public LayoutFriendlyURL updateImpl(LayoutFriendlyURL layoutFriendlyURL) {
5202                    layoutFriendlyURL = toUnwrappedModel(layoutFriendlyURL);
5203    
5204                    boolean isNew = layoutFriendlyURL.isNew();
5205    
5206                    LayoutFriendlyURLModelImpl layoutFriendlyURLModelImpl = (LayoutFriendlyURLModelImpl)layoutFriendlyURL;
5207    
5208                    if (Validator.isNull(layoutFriendlyURL.getUuid())) {
5209                            String uuid = PortalUUIDUtil.generate();
5210    
5211                            layoutFriendlyURL.setUuid(uuid);
5212                    }
5213    
5214                    ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();
5215    
5216                    Date now = new Date();
5217    
5218                    if (isNew && (layoutFriendlyURL.getCreateDate() == null)) {
5219                            if (serviceContext == null) {
5220                                    layoutFriendlyURL.setCreateDate(now);
5221                            }
5222                            else {
5223                                    layoutFriendlyURL.setCreateDate(serviceContext.getCreateDate(
5224                                                    now));
5225                            }
5226                    }
5227    
5228                    if (!layoutFriendlyURLModelImpl.hasSetModifiedDate()) {
5229                            if (serviceContext == null) {
5230                                    layoutFriendlyURL.setModifiedDate(now);
5231                            }
5232                            else {
5233                                    layoutFriendlyURL.setModifiedDate(serviceContext.getModifiedDate(
5234                                                    now));
5235                            }
5236                    }
5237    
5238                    Session session = null;
5239    
5240                    try {
5241                            session = openSession();
5242    
5243                            if (layoutFriendlyURL.isNew()) {
5244                                    session.save(layoutFriendlyURL);
5245    
5246                                    layoutFriendlyURL.setNew(false);
5247                            }
5248                            else {
5249                                    layoutFriendlyURL = (LayoutFriendlyURL)session.merge(layoutFriendlyURL);
5250                            }
5251                    }
5252                    catch (Exception e) {
5253                            throw processException(e);
5254                    }
5255                    finally {
5256                            closeSession(session);
5257                    }
5258    
5259                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
5260    
5261                    if (isNew || !LayoutFriendlyURLModelImpl.COLUMN_BITMASK_ENABLED) {
5262                            finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
5263                    }
5264    
5265                    else {
5266                            if ((layoutFriendlyURLModelImpl.getColumnBitmask() &
5267                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
5268                                    Object[] args = new Object[] {
5269                                                    layoutFriendlyURLModelImpl.getOriginalUuid()
5270                                            };
5271    
5272                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
5273                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
5274                                            args);
5275    
5276                                    args = new Object[] { layoutFriendlyURLModelImpl.getUuid() };
5277    
5278                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
5279                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
5280                                            args);
5281                            }
5282    
5283                            if ((layoutFriendlyURLModelImpl.getColumnBitmask() &
5284                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
5285                                    Object[] args = new Object[] {
5286                                                    layoutFriendlyURLModelImpl.getOriginalUuid(),
5287                                                    layoutFriendlyURLModelImpl.getOriginalCompanyId()
5288                                            };
5289    
5290                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
5291                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
5292                                            args);
5293    
5294                                    args = new Object[] {
5295                                                    layoutFriendlyURLModelImpl.getUuid(),
5296                                                    layoutFriendlyURLModelImpl.getCompanyId()
5297                                            };
5298    
5299                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
5300                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
5301                                            args);
5302                            }
5303    
5304                            if ((layoutFriendlyURLModelImpl.getColumnBitmask() &
5305                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
5306                                    Object[] args = new Object[] {
5307                                                    layoutFriendlyURLModelImpl.getOriginalGroupId()
5308                                            };
5309    
5310                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
5311                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
5312                                            args);
5313    
5314                                    args = new Object[] { layoutFriendlyURLModelImpl.getGroupId() };
5315    
5316                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
5317                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
5318                                            args);
5319                            }
5320    
5321                            if ((layoutFriendlyURLModelImpl.getColumnBitmask() &
5322                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
5323                                    Object[] args = new Object[] {
5324                                                    layoutFriendlyURLModelImpl.getOriginalCompanyId()
5325                                            };
5326    
5327                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_COMPANYID, args);
5328                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
5329                                            args);
5330    
5331                                    args = new Object[] { layoutFriendlyURLModelImpl.getCompanyId() };
5332    
5333                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_COMPANYID, args);
5334                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
5335                                            args);
5336                            }
5337    
5338                            if ((layoutFriendlyURLModelImpl.getColumnBitmask() &
5339                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PLID.getColumnBitmask()) != 0) {
5340                                    Object[] args = new Object[] {
5341                                                    layoutFriendlyURLModelImpl.getOriginalPlid()
5342                                            };
5343    
5344                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_PLID, args);
5345                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PLID,
5346                                            args);
5347    
5348                                    args = new Object[] { layoutFriendlyURLModelImpl.getPlid() };
5349    
5350                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_PLID, args);
5351                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PLID,
5352                                            args);
5353                            }
5354    
5355                            if ((layoutFriendlyURLModelImpl.getColumnBitmask() &
5356                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_F.getColumnBitmask()) != 0) {
5357                                    Object[] args = new Object[] {
5358                                                    layoutFriendlyURLModelImpl.getOriginalPlid(),
5359                                                    layoutFriendlyURLModelImpl.getOriginalFriendlyURL()
5360                                            };
5361    
5362                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_P_F, args);
5363                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_F,
5364                                            args);
5365    
5366                                    args = new Object[] {
5367                                                    layoutFriendlyURLModelImpl.getPlid(),
5368                                                    layoutFriendlyURLModelImpl.getFriendlyURL()
5369                                            };
5370    
5371                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_P_F, args);
5372                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_F,
5373                                            args);
5374                            }
5375    
5376                            if ((layoutFriendlyURLModelImpl.getColumnBitmask() &
5377                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_F.getColumnBitmask()) != 0) {
5378                                    Object[] args = new Object[] {
5379                                                    layoutFriendlyURLModelImpl.getOriginalGroupId(),
5380                                                    layoutFriendlyURLModelImpl.getOriginalPrivateLayout(),
5381                                                    layoutFriendlyURLModelImpl.getOriginalFriendlyURL()
5382                                            };
5383    
5384                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_P_F, args);
5385                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_F,
5386                                            args);
5387    
5388                                    args = new Object[] {
5389                                                    layoutFriendlyURLModelImpl.getGroupId(),
5390                                                    layoutFriendlyURLModelImpl.getPrivateLayout(),
5391                                                    layoutFriendlyURLModelImpl.getFriendlyURL()
5392                                            };
5393    
5394                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_P_F, args);
5395                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_F,
5396                                            args);
5397                            }
5398                    }
5399    
5400                    entityCache.putResult(LayoutFriendlyURLModelImpl.ENTITY_CACHE_ENABLED,
5401                            LayoutFriendlyURLImpl.class, layoutFriendlyURL.getPrimaryKey(),
5402                            layoutFriendlyURL, false);
5403    
5404                    clearUniqueFindersCache(layoutFriendlyURLModelImpl);
5405                    cacheUniqueFindersCache(layoutFriendlyURLModelImpl, isNew);
5406    
5407                    layoutFriendlyURL.resetOriginalValues();
5408    
5409                    return layoutFriendlyURL;
5410            }
5411    
5412            protected LayoutFriendlyURL toUnwrappedModel(
5413                    LayoutFriendlyURL layoutFriendlyURL) {
5414                    if (layoutFriendlyURL instanceof LayoutFriendlyURLImpl) {
5415                            return layoutFriendlyURL;
5416                    }
5417    
5418                    LayoutFriendlyURLImpl layoutFriendlyURLImpl = new LayoutFriendlyURLImpl();
5419    
5420                    layoutFriendlyURLImpl.setNew(layoutFriendlyURL.isNew());
5421                    layoutFriendlyURLImpl.setPrimaryKey(layoutFriendlyURL.getPrimaryKey());
5422    
5423                    layoutFriendlyURLImpl.setMvccVersion(layoutFriendlyURL.getMvccVersion());
5424                    layoutFriendlyURLImpl.setUuid(layoutFriendlyURL.getUuid());
5425                    layoutFriendlyURLImpl.setLayoutFriendlyURLId(layoutFriendlyURL.getLayoutFriendlyURLId());
5426                    layoutFriendlyURLImpl.setGroupId(layoutFriendlyURL.getGroupId());
5427                    layoutFriendlyURLImpl.setCompanyId(layoutFriendlyURL.getCompanyId());
5428                    layoutFriendlyURLImpl.setUserId(layoutFriendlyURL.getUserId());
5429                    layoutFriendlyURLImpl.setUserName(layoutFriendlyURL.getUserName());
5430                    layoutFriendlyURLImpl.setCreateDate(layoutFriendlyURL.getCreateDate());
5431                    layoutFriendlyURLImpl.setModifiedDate(layoutFriendlyURL.getModifiedDate());
5432                    layoutFriendlyURLImpl.setPlid(layoutFriendlyURL.getPlid());
5433                    layoutFriendlyURLImpl.setPrivateLayout(layoutFriendlyURL.isPrivateLayout());
5434                    layoutFriendlyURLImpl.setFriendlyURL(layoutFriendlyURL.getFriendlyURL());
5435                    layoutFriendlyURLImpl.setLanguageId(layoutFriendlyURL.getLanguageId());
5436                    layoutFriendlyURLImpl.setLastPublishDate(layoutFriendlyURL.getLastPublishDate());
5437    
5438                    return layoutFriendlyURLImpl;
5439            }
5440    
5441            /**
5442             * Returns the layout friendly u r l with the primary key or throws a {@link com.liferay.portal.kernel.exception.NoSuchModelException} if it could not be found.
5443             *
5444             * @param primaryKey the primary key of the layout friendly u r l
5445             * @return the layout friendly u r l
5446             * @throws NoSuchLayoutFriendlyURLException if a layout friendly u r l with the primary key could not be found
5447             */
5448            @Override
5449            public LayoutFriendlyURL findByPrimaryKey(Serializable primaryKey)
5450                    throws NoSuchLayoutFriendlyURLException {
5451                    LayoutFriendlyURL layoutFriendlyURL = fetchByPrimaryKey(primaryKey);
5452    
5453                    if (layoutFriendlyURL == null) {
5454                            if (_log.isDebugEnabled()) {
5455                                    _log.debug(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
5456                            }
5457    
5458                            throw new NoSuchLayoutFriendlyURLException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
5459                                    primaryKey);
5460                    }
5461    
5462                    return layoutFriendlyURL;
5463            }
5464    
5465            /**
5466             * Returns the layout friendly u r l with the primary key or throws a {@link NoSuchLayoutFriendlyURLException} if it could not be found.
5467             *
5468             * @param layoutFriendlyURLId the primary key of the layout friendly u r l
5469             * @return the layout friendly u r l
5470             * @throws NoSuchLayoutFriendlyURLException if a layout friendly u r l with the primary key could not be found
5471             */
5472            @Override
5473            public LayoutFriendlyURL findByPrimaryKey(long layoutFriendlyURLId)
5474                    throws NoSuchLayoutFriendlyURLException {
5475                    return findByPrimaryKey((Serializable)layoutFriendlyURLId);
5476            }
5477    
5478            /**
5479             * Returns the layout friendly u r l with the primary key or returns <code>null</code> if it could not be found.
5480             *
5481             * @param primaryKey the primary key of the layout friendly u r l
5482             * @return the layout friendly u r l, or <code>null</code> if a layout friendly u r l with the primary key could not be found
5483             */
5484            @Override
5485            public LayoutFriendlyURL fetchByPrimaryKey(Serializable primaryKey) {
5486                    LayoutFriendlyURL layoutFriendlyURL = (LayoutFriendlyURL)entityCache.getResult(LayoutFriendlyURLModelImpl.ENTITY_CACHE_ENABLED,
5487                                    LayoutFriendlyURLImpl.class, primaryKey);
5488    
5489                    if (layoutFriendlyURL == _nullLayoutFriendlyURL) {
5490                            return null;
5491                    }
5492    
5493                    if (layoutFriendlyURL == null) {
5494                            Session session = null;
5495    
5496                            try {
5497                                    session = openSession();
5498    
5499                                    layoutFriendlyURL = (LayoutFriendlyURL)session.get(LayoutFriendlyURLImpl.class,
5500                                                    primaryKey);
5501    
5502                                    if (layoutFriendlyURL != null) {
5503                                            cacheResult(layoutFriendlyURL);
5504                                    }
5505                                    else {
5506                                            entityCache.putResult(LayoutFriendlyURLModelImpl.ENTITY_CACHE_ENABLED,
5507                                                    LayoutFriendlyURLImpl.class, primaryKey,
5508                                                    _nullLayoutFriendlyURL);
5509                                    }
5510                            }
5511                            catch (Exception e) {
5512                                    entityCache.removeResult(LayoutFriendlyURLModelImpl.ENTITY_CACHE_ENABLED,
5513                                            LayoutFriendlyURLImpl.class, primaryKey);
5514    
5515                                    throw processException(e);
5516                            }
5517                            finally {
5518                                    closeSession(session);
5519                            }
5520                    }
5521    
5522                    return layoutFriendlyURL;
5523            }
5524    
5525            /**
5526             * Returns the layout friendly u r l with the primary key or returns <code>null</code> if it could not be found.
5527             *
5528             * @param layoutFriendlyURLId the primary key of the layout friendly u r l
5529             * @return the layout friendly u r l, or <code>null</code> if a layout friendly u r l with the primary key could not be found
5530             */
5531            @Override
5532            public LayoutFriendlyURL fetchByPrimaryKey(long layoutFriendlyURLId) {
5533                    return fetchByPrimaryKey((Serializable)layoutFriendlyURLId);
5534            }
5535    
5536            @Override
5537            public Map<Serializable, LayoutFriendlyURL> fetchByPrimaryKeys(
5538                    Set<Serializable> primaryKeys) {
5539                    if (primaryKeys.isEmpty()) {
5540                            return Collections.emptyMap();
5541                    }
5542    
5543                    Map<Serializable, LayoutFriendlyURL> map = new HashMap<Serializable, LayoutFriendlyURL>();
5544    
5545                    if (primaryKeys.size() == 1) {
5546                            Iterator<Serializable> iterator = primaryKeys.iterator();
5547    
5548                            Serializable primaryKey = iterator.next();
5549    
5550                            LayoutFriendlyURL layoutFriendlyURL = fetchByPrimaryKey(primaryKey);
5551    
5552                            if (layoutFriendlyURL != null) {
5553                                    map.put(primaryKey, layoutFriendlyURL);
5554                            }
5555    
5556                            return map;
5557                    }
5558    
5559                    Set<Serializable> uncachedPrimaryKeys = null;
5560    
5561                    for (Serializable primaryKey : primaryKeys) {
5562                            LayoutFriendlyURL layoutFriendlyURL = (LayoutFriendlyURL)entityCache.getResult(LayoutFriendlyURLModelImpl.ENTITY_CACHE_ENABLED,
5563                                            LayoutFriendlyURLImpl.class, primaryKey);
5564    
5565                            if (layoutFriendlyURL == null) {
5566                                    if (uncachedPrimaryKeys == null) {
5567                                            uncachedPrimaryKeys = new HashSet<Serializable>();
5568                                    }
5569    
5570                                    uncachedPrimaryKeys.add(primaryKey);
5571                            }
5572                            else {
5573                                    map.put(primaryKey, layoutFriendlyURL);
5574                            }
5575                    }
5576    
5577                    if (uncachedPrimaryKeys == null) {
5578                            return map;
5579                    }
5580    
5581                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
5582                                    1);
5583    
5584                    query.append(_SQL_SELECT_LAYOUTFRIENDLYURL_WHERE_PKS_IN);
5585    
5586                    for (Serializable primaryKey : uncachedPrimaryKeys) {
5587                            query.append(String.valueOf(primaryKey));
5588    
5589                            query.append(StringPool.COMMA);
5590                    }
5591    
5592                    query.setIndex(query.index() - 1);
5593    
5594                    query.append(StringPool.CLOSE_PARENTHESIS);
5595    
5596                    String sql = query.toString();
5597    
5598                    Session session = null;
5599    
5600                    try {
5601                            session = openSession();
5602    
5603                            Query q = session.createQuery(sql);
5604    
5605                            for (LayoutFriendlyURL layoutFriendlyURL : (List<LayoutFriendlyURL>)q.list()) {
5606                                    map.put(layoutFriendlyURL.getPrimaryKeyObj(), layoutFriendlyURL);
5607    
5608                                    cacheResult(layoutFriendlyURL);
5609    
5610                                    uncachedPrimaryKeys.remove(layoutFriendlyURL.getPrimaryKeyObj());
5611                            }
5612    
5613                            for (Serializable primaryKey : uncachedPrimaryKeys) {
5614                                    entityCache.putResult(LayoutFriendlyURLModelImpl.ENTITY_CACHE_ENABLED,
5615                                            LayoutFriendlyURLImpl.class, primaryKey,
5616                                            _nullLayoutFriendlyURL);
5617                            }
5618                    }
5619                    catch (Exception e) {
5620                            throw processException(e);
5621                    }
5622                    finally {
5623                            closeSession(session);
5624                    }
5625    
5626                    return map;
5627            }
5628    
5629            /**
5630             * Returns all the layout friendly u r ls.
5631             *
5632             * @return the layout friendly u r ls
5633             */
5634            @Override
5635            public List<LayoutFriendlyURL> findAll() {
5636                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
5637            }
5638    
5639            /**
5640             * Returns a range of all the layout friendly u r ls.
5641             *
5642             * <p>
5643             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link LayoutFriendlyURLModelImpl}. 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.
5644             * </p>
5645             *
5646             * @param start the lower bound of the range of layout friendly u r ls
5647             * @param end the upper bound of the range of layout friendly u r ls (not inclusive)
5648             * @return the range of layout friendly u r ls
5649             */
5650            @Override
5651            public List<LayoutFriendlyURL> findAll(int start, int end) {
5652                    return findAll(start, end, null);
5653            }
5654    
5655            /**
5656             * Returns an ordered range of all the layout friendly u r ls.
5657             *
5658             * <p>
5659             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link LayoutFriendlyURLModelImpl}. 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.
5660             * </p>
5661             *
5662             * @param start the lower bound of the range of layout friendly u r ls
5663             * @param end the upper bound of the range of layout friendly u r ls (not inclusive)
5664             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5665             * @return the ordered range of layout friendly u r ls
5666             */
5667            @Override
5668            public List<LayoutFriendlyURL> findAll(int start, int end,
5669                    OrderByComparator<LayoutFriendlyURL> orderByComparator) {
5670                    return findAll(start, end, orderByComparator, true);
5671            }
5672    
5673            /**
5674             * Returns an ordered range of all the layout friendly u r ls.
5675             *
5676             * <p>
5677             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link LayoutFriendlyURLModelImpl}. 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.
5678             * </p>
5679             *
5680             * @param start the lower bound of the range of layout friendly u r ls
5681             * @param end the upper bound of the range of layout friendly u r ls (not inclusive)
5682             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5683             * @param retrieveFromCache whether to retrieve from the finder cache
5684             * @return the ordered range of layout friendly u r ls
5685             */
5686            @Override
5687            public List<LayoutFriendlyURL> findAll(int start, int end,
5688                    OrderByComparator<LayoutFriendlyURL> orderByComparator,
5689                    boolean retrieveFromCache) {
5690                    boolean pagination = true;
5691                    FinderPath finderPath = null;
5692                    Object[] finderArgs = null;
5693    
5694                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5695                                    (orderByComparator == null)) {
5696                            pagination = false;
5697                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
5698                            finderArgs = FINDER_ARGS_EMPTY;
5699                    }
5700                    else {
5701                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
5702                            finderArgs = new Object[] { start, end, orderByComparator };
5703                    }
5704    
5705                    List<LayoutFriendlyURL> list = null;
5706    
5707                    if (retrieveFromCache) {
5708                            list = (List<LayoutFriendlyURL>)finderCache.getResult(finderPath,
5709                                            finderArgs, this);
5710                    }
5711    
5712                    if (list == null) {
5713                            StringBundler query = null;
5714                            String sql = null;
5715    
5716                            if (orderByComparator != null) {
5717                                    query = new StringBundler(2 +
5718                                                    (orderByComparator.getOrderByFields().length * 2));
5719    
5720                                    query.append(_SQL_SELECT_LAYOUTFRIENDLYURL);
5721    
5722                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5723                                            orderByComparator);
5724    
5725                                    sql = query.toString();
5726                            }
5727                            else {
5728                                    sql = _SQL_SELECT_LAYOUTFRIENDLYURL;
5729    
5730                                    if (pagination) {
5731                                            sql = sql.concat(LayoutFriendlyURLModelImpl.ORDER_BY_JPQL);
5732                                    }
5733                            }
5734    
5735                            Session session = null;
5736    
5737                            try {
5738                                    session = openSession();
5739    
5740                                    Query q = session.createQuery(sql);
5741    
5742                                    if (!pagination) {
5743                                            list = (List<LayoutFriendlyURL>)QueryUtil.list(q,
5744                                                            getDialect(), start, end, false);
5745    
5746                                            Collections.sort(list);
5747    
5748                                            list = Collections.unmodifiableList(list);
5749                                    }
5750                                    else {
5751                                            list = (List<LayoutFriendlyURL>)QueryUtil.list(q,
5752                                                            getDialect(), start, end);
5753                                    }
5754    
5755                                    cacheResult(list);
5756    
5757                                    finderCache.putResult(finderPath, finderArgs, list);
5758                            }
5759                            catch (Exception e) {
5760                                    finderCache.removeResult(finderPath, finderArgs);
5761    
5762                                    throw processException(e);
5763                            }
5764                            finally {
5765                                    closeSession(session);
5766                            }
5767                    }
5768    
5769                    return list;
5770            }
5771    
5772            /**
5773             * Removes all the layout friendly u r ls from the database.
5774             *
5775             */
5776            @Override
5777            public void removeAll() {
5778                    for (LayoutFriendlyURL layoutFriendlyURL : findAll()) {
5779                            remove(layoutFriendlyURL);
5780                    }
5781            }
5782    
5783            /**
5784             * Returns the number of layout friendly u r ls.
5785             *
5786             * @return the number of layout friendly u r ls
5787             */
5788            @Override
5789            public int countAll() {
5790                    Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
5791                                    FINDER_ARGS_EMPTY, this);
5792    
5793                    if (count == null) {
5794                            Session session = null;
5795    
5796                            try {
5797                                    session = openSession();
5798    
5799                                    Query q = session.createQuery(_SQL_COUNT_LAYOUTFRIENDLYURL);
5800    
5801                                    count = (Long)q.uniqueResult();
5802    
5803                                    finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
5804                                            count);
5805                            }
5806                            catch (Exception e) {
5807                                    finderCache.removeResult(FINDER_PATH_COUNT_ALL,
5808                                            FINDER_ARGS_EMPTY);
5809    
5810                                    throw processException(e);
5811                            }
5812                            finally {
5813                                    closeSession(session);
5814                            }
5815                    }
5816    
5817                    return count.intValue();
5818            }
5819    
5820            @Override
5821            public Set<String> getBadColumnNames() {
5822                    return _badColumnNames;
5823            }
5824    
5825            @Override
5826            protected Map<String, Integer> getTableColumnsMap() {
5827                    return LayoutFriendlyURLModelImpl.TABLE_COLUMNS_MAP;
5828            }
5829    
5830            /**
5831             * Initializes the layout friendly u r l persistence.
5832             */
5833            public void afterPropertiesSet() {
5834            }
5835    
5836            public void destroy() {
5837                    entityCache.removeCache(LayoutFriendlyURLImpl.class.getName());
5838                    finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
5839                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
5840                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
5841            }
5842    
5843            @BeanReference(type = CompanyProviderWrapper.class)
5844            protected CompanyProvider companyProvider;
5845            protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
5846            protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
5847            private static final String _SQL_SELECT_LAYOUTFRIENDLYURL = "SELECT layoutFriendlyURL FROM LayoutFriendlyURL layoutFriendlyURL";
5848            private static final String _SQL_SELECT_LAYOUTFRIENDLYURL_WHERE_PKS_IN = "SELECT layoutFriendlyURL FROM LayoutFriendlyURL layoutFriendlyURL WHERE layoutFriendlyURLId IN (";
5849            private static final String _SQL_SELECT_LAYOUTFRIENDLYURL_WHERE = "SELECT layoutFriendlyURL FROM LayoutFriendlyURL layoutFriendlyURL WHERE ";
5850            private static final String _SQL_COUNT_LAYOUTFRIENDLYURL = "SELECT COUNT(layoutFriendlyURL) FROM LayoutFriendlyURL layoutFriendlyURL";
5851            private static final String _SQL_COUNT_LAYOUTFRIENDLYURL_WHERE = "SELECT COUNT(layoutFriendlyURL) FROM LayoutFriendlyURL layoutFriendlyURL WHERE ";
5852            private static final String _ORDER_BY_ENTITY_ALIAS = "layoutFriendlyURL.";
5853            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No LayoutFriendlyURL exists with the primary key ";
5854            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No LayoutFriendlyURL exists with the key {";
5855            private static final Log _log = LogFactoryUtil.getLog(LayoutFriendlyURLPersistenceImpl.class);
5856            private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
5857                                    "uuid"
5858                            });
5859            private static final LayoutFriendlyURL _nullLayoutFriendlyURL = new LayoutFriendlyURLImpl() {
5860                            @Override
5861                            public Object clone() {
5862                                    return this;
5863                            }
5864    
5865                            @Override
5866                            public CacheModel<LayoutFriendlyURL> toCacheModel() {
5867                                    return _nullLayoutFriendlyURLCacheModel;
5868                            }
5869                    };
5870    
5871            private static final CacheModel<LayoutFriendlyURL> _nullLayoutFriendlyURLCacheModel =
5872                    new NullCacheModel();
5873    
5874            private static class NullCacheModel implements CacheModel<LayoutFriendlyURL>,
5875                    MVCCModel {
5876                    @Override
5877                    public long getMvccVersion() {
5878                            return -1;
5879                    }
5880    
5881                    @Override
5882                    public void setMvccVersion(long mvccVersion) {
5883                    }
5884    
5885                    @Override
5886                    public LayoutFriendlyURL toEntityModel() {
5887                            return _nullLayoutFriendlyURL;
5888                    }
5889            }
5890    }