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