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