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