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