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