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