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