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