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