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