001    /**
002     * Copyright (c) 2000-2012 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.StringBundler;
033    import com.liferay.portal.kernel.util.StringPool;
034    import com.liferay.portal.kernel.util.StringUtil;
035    import com.liferay.portal.kernel.util.UnmodifiableList;
036    import com.liferay.portal.model.CacheModel;
037    import com.liferay.portal.model.ModelListener;
038    import com.liferay.portal.model.Website;
039    import com.liferay.portal.model.impl.WebsiteImpl;
040    import com.liferay.portal.model.impl.WebsiteModelImpl;
041    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
042    
043    import java.io.Serializable;
044    
045    import java.util.ArrayList;
046    import java.util.Collections;
047    import java.util.List;
048    
049    /**
050     * The persistence implementation for the website service.
051     *
052     * <p>
053     * Caching information and settings can be found in <code>portal.properties</code>
054     * </p>
055     *
056     * @author Brian Wing Shun Chan
057     * @see WebsitePersistence
058     * @see WebsiteUtil
059     * @generated
060     */
061    public class WebsitePersistenceImpl extends BasePersistenceImpl<Website>
062            implements WebsitePersistence {
063            /*
064             * NOTE FOR DEVELOPERS:
065             *
066             * 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.
067             */
068            public static final String FINDER_CLASS_NAME_ENTITY = WebsiteImpl.class.getName();
069            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
070                    ".List1";
071            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
072                    ".List2";
073            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(WebsiteModelImpl.ENTITY_CACHE_ENABLED,
074                            WebsiteModelImpl.FINDER_CACHE_ENABLED, WebsiteImpl.class,
075                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
076            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(WebsiteModelImpl.ENTITY_CACHE_ENABLED,
077                            WebsiteModelImpl.FINDER_CACHE_ENABLED, WebsiteImpl.class,
078                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
079            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(WebsiteModelImpl.ENTITY_CACHE_ENABLED,
080                            WebsiteModelImpl.FINDER_CACHE_ENABLED, Long.class,
081                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
082            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
083                    new FinderPath(WebsiteModelImpl.ENTITY_CACHE_ENABLED,
084                            WebsiteModelImpl.FINDER_CACHE_ENABLED, WebsiteImpl.class,
085                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
086                            new String[] {
087                                    Long.class.getName(),
088                                    
089                            Integer.class.getName(), Integer.class.getName(),
090                                    OrderByComparator.class.getName()
091                            });
092            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
093                    new FinderPath(WebsiteModelImpl.ENTITY_CACHE_ENABLED,
094                            WebsiteModelImpl.FINDER_CACHE_ENABLED, WebsiteImpl.class,
095                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
096                            new String[] { Long.class.getName() },
097                            WebsiteModelImpl.COMPANYID_COLUMN_BITMASK |
098                            WebsiteModelImpl.CREATEDATE_COLUMN_BITMASK);
099            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(WebsiteModelImpl.ENTITY_CACHE_ENABLED,
100                            WebsiteModelImpl.FINDER_CACHE_ENABLED, Long.class,
101                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
102                            new String[] { Long.class.getName() });
103    
104            /**
105             * Returns all the websites where companyId = &#63;.
106             *
107             * @param companyId the company ID
108             * @return the matching websites
109             * @throws SystemException if a system exception occurred
110             */
111            public List<Website> findByCompanyId(long companyId)
112                    throws SystemException {
113                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
114                            null);
115            }
116    
117            /**
118             * Returns a range of all the websites where companyId = &#63;.
119             *
120             * <p>
121             * 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.
122             * </p>
123             *
124             * @param companyId the company ID
125             * @param start the lower bound of the range of websites
126             * @param end the upper bound of the range of websites (not inclusive)
127             * @return the range of matching websites
128             * @throws SystemException if a system exception occurred
129             */
130            public List<Website> findByCompanyId(long companyId, int start, int end)
131                    throws SystemException {
132                    return findByCompanyId(companyId, start, end, null);
133            }
134    
135            /**
136             * Returns an ordered range of all the websites where companyId = &#63;.
137             *
138             * <p>
139             * 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.
140             * </p>
141             *
142             * @param companyId the company ID
143             * @param start the lower bound of the range of websites
144             * @param end the upper bound of the range of websites (not inclusive)
145             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
146             * @return the ordered range of matching websites
147             * @throws SystemException if a system exception occurred
148             */
149            public List<Website> findByCompanyId(long companyId, int start, int end,
150                    OrderByComparator orderByComparator) throws SystemException {
151                    boolean pagination = true;
152                    FinderPath finderPath = null;
153                    Object[] finderArgs = null;
154    
155                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
156                                    (orderByComparator == null)) {
157                            pagination = false;
158                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
159                            finderArgs = new Object[] { companyId };
160                    }
161                    else {
162                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
163                            finderArgs = new Object[] { companyId, start, end, orderByComparator };
164                    }
165    
166                    List<Website> list = (List<Website>)FinderCacheUtil.getResult(finderPath,
167                                    finderArgs, this);
168    
169                    if ((list != null) && !list.isEmpty()) {
170                            for (Website website : list) {
171                                    if ((companyId != website.getCompanyId())) {
172                                            list = null;
173    
174                                            break;
175                                    }
176                            }
177                    }
178    
179                    if (list == null) {
180                            StringBundler query = null;
181    
182                            if (orderByComparator != null) {
183                                    query = new StringBundler(3 +
184                                                    (orderByComparator.getOrderByFields().length * 3));
185                            }
186                            else {
187                                    query = new StringBundler(3);
188                            }
189    
190                            query.append(_SQL_SELECT_WEBSITE_WHERE);
191    
192                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
193    
194                            if (orderByComparator != null) {
195                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
196                                            orderByComparator);
197                            }
198                            else
199                             if (pagination) {
200                                    query.append(WebsiteModelImpl.ORDER_BY_JPQL);
201                            }
202    
203                            String sql = query.toString();
204    
205                            Session session = null;
206    
207                            try {
208                                    session = openSession();
209    
210                                    Query q = session.createQuery(sql);
211    
212                                    QueryPos qPos = QueryPos.getInstance(q);
213    
214                                    qPos.add(companyId);
215    
216                                    if (!pagination) {
217                                            list = (List<Website>)QueryUtil.list(q, getDialect(),
218                                                            start, end, false);
219    
220                                            Collections.sort(list);
221    
222                                            list = new UnmodifiableList<Website>(list);
223                                    }
224                                    else {
225                                            list = (List<Website>)QueryUtil.list(q, getDialect(),
226                                                            start, end);
227                                    }
228    
229                                    cacheResult(list);
230    
231                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
232                            }
233                            catch (Exception e) {
234                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
235    
236                                    throw processException(e);
237                            }
238                            finally {
239                                    closeSession(session);
240                            }
241                    }
242    
243                    return list;
244            }
245    
246            /**
247             * Returns the first website in the ordered set where companyId = &#63;.
248             *
249             * @param companyId the company ID
250             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
251             * @return the first matching website
252             * @throws com.liferay.portal.NoSuchWebsiteException if a matching website could not be found
253             * @throws SystemException if a system exception occurred
254             */
255            public Website findByCompanyId_First(long companyId,
256                    OrderByComparator orderByComparator)
257                    throws NoSuchWebsiteException, SystemException {
258                    Website website = fetchByCompanyId_First(companyId, orderByComparator);
259    
260                    if (website != null) {
261                            return website;
262                    }
263    
264                    StringBundler msg = new StringBundler(4);
265    
266                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
267    
268                    msg.append("companyId=");
269                    msg.append(companyId);
270    
271                    msg.append(StringPool.CLOSE_CURLY_BRACE);
272    
273                    throw new NoSuchWebsiteException(msg.toString());
274            }
275    
276            /**
277             * Returns the first website in the ordered set where companyId = &#63;.
278             *
279             * @param companyId the company ID
280             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
281             * @return the first matching website, or <code>null</code> if a matching website could not be found
282             * @throws SystemException if a system exception occurred
283             */
284            public Website fetchByCompanyId_First(long companyId,
285                    OrderByComparator orderByComparator) throws SystemException {
286                    List<Website> list = findByCompanyId(companyId, 0, 1, orderByComparator);
287    
288                    if (!list.isEmpty()) {
289                            return list.get(0);
290                    }
291    
292                    return null;
293            }
294    
295            /**
296             * Returns the last website in the ordered set where companyId = &#63;.
297             *
298             * @param companyId the company ID
299             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
300             * @return the last matching website
301             * @throws com.liferay.portal.NoSuchWebsiteException if a matching website could not be found
302             * @throws SystemException if a system exception occurred
303             */
304            public Website findByCompanyId_Last(long companyId,
305                    OrderByComparator orderByComparator)
306                    throws NoSuchWebsiteException, SystemException {
307                    Website website = fetchByCompanyId_Last(companyId, orderByComparator);
308    
309                    if (website != null) {
310                            return website;
311                    }
312    
313                    StringBundler msg = new StringBundler(4);
314    
315                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
316    
317                    msg.append("companyId=");
318                    msg.append(companyId);
319    
320                    msg.append(StringPool.CLOSE_CURLY_BRACE);
321    
322                    throw new NoSuchWebsiteException(msg.toString());
323            }
324    
325            /**
326             * Returns the last website in the ordered set where companyId = &#63;.
327             *
328             * @param companyId the company ID
329             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
330             * @return the last matching website, or <code>null</code> if a matching website could not be found
331             * @throws SystemException if a system exception occurred
332             */
333            public Website fetchByCompanyId_Last(long companyId,
334                    OrderByComparator orderByComparator) throws SystemException {
335                    int count = countByCompanyId(companyId);
336    
337                    List<Website> list = findByCompanyId(companyId, count - 1, count,
338                                    orderByComparator);
339    
340                    if (!list.isEmpty()) {
341                            return list.get(0);
342                    }
343    
344                    return null;
345            }
346    
347            /**
348             * Returns the websites before and after the current website in the ordered set where companyId = &#63;.
349             *
350             * @param websiteId the primary key of the current website
351             * @param companyId the company ID
352             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
353             * @return the previous, current, and next website
354             * @throws com.liferay.portal.NoSuchWebsiteException if a website with the primary key could not be found
355             * @throws SystemException if a system exception occurred
356             */
357            public Website[] findByCompanyId_PrevAndNext(long websiteId,
358                    long companyId, OrderByComparator orderByComparator)
359                    throws NoSuchWebsiteException, SystemException {
360                    Website website = findByPrimaryKey(websiteId);
361    
362                    Session session = null;
363    
364                    try {
365                            session = openSession();
366    
367                            Website[] array = new WebsiteImpl[3];
368    
369                            array[0] = getByCompanyId_PrevAndNext(session, website, companyId,
370                                            orderByComparator, true);
371    
372                            array[1] = website;
373    
374                            array[2] = getByCompanyId_PrevAndNext(session, website, companyId,
375                                            orderByComparator, false);
376    
377                            return array;
378                    }
379                    catch (Exception e) {
380                            throw processException(e);
381                    }
382                    finally {
383                            closeSession(session);
384                    }
385            }
386    
387            protected Website getByCompanyId_PrevAndNext(Session session,
388                    Website website, long companyId, OrderByComparator orderByComparator,
389                    boolean previous) {
390                    StringBundler query = null;
391    
392                    if (orderByComparator != null) {
393                            query = new StringBundler(6 +
394                                            (orderByComparator.getOrderByFields().length * 6));
395                    }
396                    else {
397                            query = new StringBundler(3);
398                    }
399    
400                    query.append(_SQL_SELECT_WEBSITE_WHERE);
401    
402                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
403    
404                    if (orderByComparator != null) {
405                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
406    
407                            if (orderByConditionFields.length > 0) {
408                                    query.append(WHERE_AND);
409                            }
410    
411                            for (int i = 0; i < orderByConditionFields.length; i++) {
412                                    query.append(_ORDER_BY_ENTITY_ALIAS);
413                                    query.append(orderByConditionFields[i]);
414    
415                                    if ((i + 1) < orderByConditionFields.length) {
416                                            if (orderByComparator.isAscending() ^ previous) {
417                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
418                                            }
419                                            else {
420                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
421                                            }
422                                    }
423                                    else {
424                                            if (orderByComparator.isAscending() ^ previous) {
425                                                    query.append(WHERE_GREATER_THAN);
426                                            }
427                                            else {
428                                                    query.append(WHERE_LESSER_THAN);
429                                            }
430                                    }
431                            }
432    
433                            query.append(ORDER_BY_CLAUSE);
434    
435                            String[] orderByFields = orderByComparator.getOrderByFields();
436    
437                            for (int i = 0; i < orderByFields.length; i++) {
438                                    query.append(_ORDER_BY_ENTITY_ALIAS);
439                                    query.append(orderByFields[i]);
440    
441                                    if ((i + 1) < orderByFields.length) {
442                                            if (orderByComparator.isAscending() ^ previous) {
443                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
444                                            }
445                                            else {
446                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
447                                            }
448                                    }
449                                    else {
450                                            if (orderByComparator.isAscending() ^ previous) {
451                                                    query.append(ORDER_BY_ASC);
452                                            }
453                                            else {
454                                                    query.append(ORDER_BY_DESC);
455                                            }
456                                    }
457                            }
458                    }
459                    else {
460                            query.append(WebsiteModelImpl.ORDER_BY_JPQL);
461                    }
462    
463                    String sql = query.toString();
464    
465                    Query q = session.createQuery(sql);
466    
467                    q.setFirstResult(0);
468                    q.setMaxResults(2);
469    
470                    QueryPos qPos = QueryPos.getInstance(q);
471    
472                    qPos.add(companyId);
473    
474                    if (orderByComparator != null) {
475                            Object[] values = orderByComparator.getOrderByConditionValues(website);
476    
477                            for (Object value : values) {
478                                    qPos.add(value);
479                            }
480                    }
481    
482                    List<Website> list = q.list();
483    
484                    if (list.size() == 2) {
485                            return list.get(1);
486                    }
487                    else {
488                            return null;
489                    }
490            }
491    
492            /**
493             * Removes all the websites where companyId = &#63; from the database.
494             *
495             * @param companyId the company ID
496             * @throws SystemException if a system exception occurred
497             */
498            public void removeByCompanyId(long companyId) throws SystemException {
499                    for (Website website : findByCompanyId(companyId, QueryUtil.ALL_POS,
500                                    QueryUtil.ALL_POS, null)) {
501                            remove(website);
502                    }
503            }
504    
505            /**
506             * Returns the number of websites where companyId = &#63;.
507             *
508             * @param companyId the company ID
509             * @return the number of matching websites
510             * @throws SystemException if a system exception occurred
511             */
512            public int countByCompanyId(long companyId) throws SystemException {
513                    FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
514    
515                    Object[] finderArgs = new Object[] { companyId };
516    
517                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
518                                    this);
519    
520                    if (count == null) {
521                            StringBundler query = new StringBundler(2);
522    
523                            query.append(_SQL_COUNT_WEBSITE_WHERE);
524    
525                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
526    
527                            String sql = query.toString();
528    
529                            Session session = null;
530    
531                            try {
532                                    session = openSession();
533    
534                                    Query q = session.createQuery(sql);
535    
536                                    QueryPos qPos = QueryPos.getInstance(q);
537    
538                                    qPos.add(companyId);
539    
540                                    count = (Long)q.uniqueResult();
541    
542                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
543                            }
544                            catch (Exception e) {
545                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
546    
547                                    throw processException(e);
548                            }
549                            finally {
550                                    closeSession(session);
551                            }
552                    }
553    
554                    return count.intValue();
555            }
556    
557            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "website.companyId = ?";
558            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(WebsiteModelImpl.ENTITY_CACHE_ENABLED,
559                            WebsiteModelImpl.FINDER_CACHE_ENABLED, WebsiteImpl.class,
560                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUserId",
561                            new String[] {
562                                    Long.class.getName(),
563                                    
564                            Integer.class.getName(), Integer.class.getName(),
565                                    OrderByComparator.class.getName()
566                            });
567            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID =
568                    new FinderPath(WebsiteModelImpl.ENTITY_CACHE_ENABLED,
569                            WebsiteModelImpl.FINDER_CACHE_ENABLED, WebsiteImpl.class,
570                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId",
571                            new String[] { Long.class.getName() },
572                            WebsiteModelImpl.USERID_COLUMN_BITMASK |
573                            WebsiteModelImpl.CREATEDATE_COLUMN_BITMASK);
574            public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(WebsiteModelImpl.ENTITY_CACHE_ENABLED,
575                            WebsiteModelImpl.FINDER_CACHE_ENABLED, Long.class,
576                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
577                            new String[] { Long.class.getName() });
578    
579            /**
580             * Returns all the websites where userId = &#63;.
581             *
582             * @param userId the user ID
583             * @return the matching websites
584             * @throws SystemException if a system exception occurred
585             */
586            public List<Website> findByUserId(long userId) throws SystemException {
587                    return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
588            }
589    
590            /**
591             * Returns a range of all the websites where userId = &#63;.
592             *
593             * <p>
594             * 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.
595             * </p>
596             *
597             * @param userId the user ID
598             * @param start the lower bound of the range of websites
599             * @param end the upper bound of the range of websites (not inclusive)
600             * @return the range of matching websites
601             * @throws SystemException if a system exception occurred
602             */
603            public List<Website> findByUserId(long userId, int start, int end)
604                    throws SystemException {
605                    return findByUserId(userId, start, end, null);
606            }
607    
608            /**
609             * Returns an ordered range of all the websites where userId = &#63;.
610             *
611             * <p>
612             * 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.
613             * </p>
614             *
615             * @param userId the user ID
616             * @param start the lower bound of the range of websites
617             * @param end the upper bound of the range of websites (not inclusive)
618             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
619             * @return the ordered range of matching websites
620             * @throws SystemException if a system exception occurred
621             */
622            public List<Website> findByUserId(long userId, int start, int end,
623                    OrderByComparator orderByComparator) throws SystemException {
624                    boolean pagination = true;
625                    FinderPath finderPath = null;
626                    Object[] finderArgs = null;
627    
628                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
629                                    (orderByComparator == null)) {
630                            pagination = false;
631                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
632                            finderArgs = new Object[] { userId };
633                    }
634                    else {
635                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
636                            finderArgs = new Object[] { userId, start, end, orderByComparator };
637                    }
638    
639                    List<Website> list = (List<Website>)FinderCacheUtil.getResult(finderPath,
640                                    finderArgs, this);
641    
642                    if ((list != null) && !list.isEmpty()) {
643                            for (Website website : list) {
644                                    if ((userId != website.getUserId())) {
645                                            list = null;
646    
647                                            break;
648                                    }
649                            }
650                    }
651    
652                    if (list == null) {
653                            StringBundler query = null;
654    
655                            if (orderByComparator != null) {
656                                    query = new StringBundler(3 +
657                                                    (orderByComparator.getOrderByFields().length * 3));
658                            }
659                            else {
660                                    query = new StringBundler(3);
661                            }
662    
663                            query.append(_SQL_SELECT_WEBSITE_WHERE);
664    
665                            query.append(_FINDER_COLUMN_USERID_USERID_2);
666    
667                            if (orderByComparator != null) {
668                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
669                                            orderByComparator);
670                            }
671                            else
672                             if (pagination) {
673                                    query.append(WebsiteModelImpl.ORDER_BY_JPQL);
674                            }
675    
676                            String sql = query.toString();
677    
678                            Session session = null;
679    
680                            try {
681                                    session = openSession();
682    
683                                    Query q = session.createQuery(sql);
684    
685                                    QueryPos qPos = QueryPos.getInstance(q);
686    
687                                    qPos.add(userId);
688    
689                                    if (!pagination) {
690                                            list = (List<Website>)QueryUtil.list(q, getDialect(),
691                                                            start, end, false);
692    
693                                            Collections.sort(list);
694    
695                                            list = new UnmodifiableList<Website>(list);
696                                    }
697                                    else {
698                                            list = (List<Website>)QueryUtil.list(q, getDialect(),
699                                                            start, end);
700                                    }
701    
702                                    cacheResult(list);
703    
704                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
705                            }
706                            catch (Exception e) {
707                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
708    
709                                    throw processException(e);
710                            }
711                            finally {
712                                    closeSession(session);
713                            }
714                    }
715    
716                    return list;
717            }
718    
719            /**
720             * Returns the first website in the ordered set where userId = &#63;.
721             *
722             * @param userId the user ID
723             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
724             * @return the first matching website
725             * @throws com.liferay.portal.NoSuchWebsiteException if a matching website could not be found
726             * @throws SystemException if a system exception occurred
727             */
728            public Website findByUserId_First(long userId,
729                    OrderByComparator orderByComparator)
730                    throws NoSuchWebsiteException, SystemException {
731                    Website website = fetchByUserId_First(userId, orderByComparator);
732    
733                    if (website != null) {
734                            return website;
735                    }
736    
737                    StringBundler msg = new StringBundler(4);
738    
739                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
740    
741                    msg.append("userId=");
742                    msg.append(userId);
743    
744                    msg.append(StringPool.CLOSE_CURLY_BRACE);
745    
746                    throw new NoSuchWebsiteException(msg.toString());
747            }
748    
749            /**
750             * Returns the first website in the ordered set where userId = &#63;.
751             *
752             * @param userId the user ID
753             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
754             * @return the first matching website, or <code>null</code> if a matching website could not be found
755             * @throws SystemException if a system exception occurred
756             */
757            public Website fetchByUserId_First(long userId,
758                    OrderByComparator orderByComparator) throws SystemException {
759                    List<Website> list = findByUserId(userId, 0, 1, orderByComparator);
760    
761                    if (!list.isEmpty()) {
762                            return list.get(0);
763                    }
764    
765                    return null;
766            }
767    
768            /**
769             * Returns the last website in the ordered set where userId = &#63;.
770             *
771             * @param userId the user ID
772             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
773             * @return the last matching website
774             * @throws com.liferay.portal.NoSuchWebsiteException if a matching website could not be found
775             * @throws SystemException if a system exception occurred
776             */
777            public Website findByUserId_Last(long userId,
778                    OrderByComparator orderByComparator)
779                    throws NoSuchWebsiteException, SystemException {
780                    Website website = fetchByUserId_Last(userId, orderByComparator);
781    
782                    if (website != null) {
783                            return website;
784                    }
785    
786                    StringBundler msg = new StringBundler(4);
787    
788                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
789    
790                    msg.append("userId=");
791                    msg.append(userId);
792    
793                    msg.append(StringPool.CLOSE_CURLY_BRACE);
794    
795                    throw new NoSuchWebsiteException(msg.toString());
796            }
797    
798            /**
799             * Returns the last website in the ordered set where userId = &#63;.
800             *
801             * @param userId the user ID
802             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
803             * @return the last matching website, or <code>null</code> if a matching website could not be found
804             * @throws SystemException if a system exception occurred
805             */
806            public Website fetchByUserId_Last(long userId,
807                    OrderByComparator orderByComparator) throws SystemException {
808                    int count = countByUserId(userId);
809    
810                    List<Website> list = findByUserId(userId, count - 1, count,
811                                    orderByComparator);
812    
813                    if (!list.isEmpty()) {
814                            return list.get(0);
815                    }
816    
817                    return null;
818            }
819    
820            /**
821             * Returns the websites before and after the current website in the ordered set where userId = &#63;.
822             *
823             * @param websiteId the primary key of the current website
824             * @param userId the user ID
825             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
826             * @return the previous, current, and next website
827             * @throws com.liferay.portal.NoSuchWebsiteException if a website with the primary key could not be found
828             * @throws SystemException if a system exception occurred
829             */
830            public Website[] findByUserId_PrevAndNext(long websiteId, long userId,
831                    OrderByComparator orderByComparator)
832                    throws NoSuchWebsiteException, SystemException {
833                    Website website = findByPrimaryKey(websiteId);
834    
835                    Session session = null;
836    
837                    try {
838                            session = openSession();
839    
840                            Website[] array = new WebsiteImpl[3];
841    
842                            array[0] = getByUserId_PrevAndNext(session, website, userId,
843                                            orderByComparator, true);
844    
845                            array[1] = website;
846    
847                            array[2] = getByUserId_PrevAndNext(session, website, userId,
848                                            orderByComparator, false);
849    
850                            return array;
851                    }
852                    catch (Exception e) {
853                            throw processException(e);
854                    }
855                    finally {
856                            closeSession(session);
857                    }
858            }
859    
860            protected Website getByUserId_PrevAndNext(Session session, Website website,
861                    long userId, OrderByComparator orderByComparator, boolean previous) {
862                    StringBundler query = null;
863    
864                    if (orderByComparator != null) {
865                            query = new StringBundler(6 +
866                                            (orderByComparator.getOrderByFields().length * 6));
867                    }
868                    else {
869                            query = new StringBundler(3);
870                    }
871    
872                    query.append(_SQL_SELECT_WEBSITE_WHERE);
873    
874                    query.append(_FINDER_COLUMN_USERID_USERID_2);
875    
876                    if (orderByComparator != null) {
877                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
878    
879                            if (orderByConditionFields.length > 0) {
880                                    query.append(WHERE_AND);
881                            }
882    
883                            for (int i = 0; i < orderByConditionFields.length; i++) {
884                                    query.append(_ORDER_BY_ENTITY_ALIAS);
885                                    query.append(orderByConditionFields[i]);
886    
887                                    if ((i + 1) < orderByConditionFields.length) {
888                                            if (orderByComparator.isAscending() ^ previous) {
889                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
890                                            }
891                                            else {
892                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
893                                            }
894                                    }
895                                    else {
896                                            if (orderByComparator.isAscending() ^ previous) {
897                                                    query.append(WHERE_GREATER_THAN);
898                                            }
899                                            else {
900                                                    query.append(WHERE_LESSER_THAN);
901                                            }
902                                    }
903                            }
904    
905                            query.append(ORDER_BY_CLAUSE);
906    
907                            String[] orderByFields = orderByComparator.getOrderByFields();
908    
909                            for (int i = 0; i < orderByFields.length; i++) {
910                                    query.append(_ORDER_BY_ENTITY_ALIAS);
911                                    query.append(orderByFields[i]);
912    
913                                    if ((i + 1) < orderByFields.length) {
914                                            if (orderByComparator.isAscending() ^ previous) {
915                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
916                                            }
917                                            else {
918                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
919                                            }
920                                    }
921                                    else {
922                                            if (orderByComparator.isAscending() ^ previous) {
923                                                    query.append(ORDER_BY_ASC);
924                                            }
925                                            else {
926                                                    query.append(ORDER_BY_DESC);
927                                            }
928                                    }
929                            }
930                    }
931                    else {
932                            query.append(WebsiteModelImpl.ORDER_BY_JPQL);
933                    }
934    
935                    String sql = query.toString();
936    
937                    Query q = session.createQuery(sql);
938    
939                    q.setFirstResult(0);
940                    q.setMaxResults(2);
941    
942                    QueryPos qPos = QueryPos.getInstance(q);
943    
944                    qPos.add(userId);
945    
946                    if (orderByComparator != null) {
947                            Object[] values = orderByComparator.getOrderByConditionValues(website);
948    
949                            for (Object value : values) {
950                                    qPos.add(value);
951                            }
952                    }
953    
954                    List<Website> list = q.list();
955    
956                    if (list.size() == 2) {
957                            return list.get(1);
958                    }
959                    else {
960                            return null;
961                    }
962            }
963    
964            /**
965             * Removes all the websites where userId = &#63; from the database.
966             *
967             * @param userId the user ID
968             * @throws SystemException if a system exception occurred
969             */
970            public void removeByUserId(long userId) throws SystemException {
971                    for (Website website : findByUserId(userId, QueryUtil.ALL_POS,
972                                    QueryUtil.ALL_POS, null)) {
973                            remove(website);
974                    }
975            }
976    
977            /**
978             * Returns the number of websites where userId = &#63;.
979             *
980             * @param userId the user ID
981             * @return the number of matching websites
982             * @throws SystemException if a system exception occurred
983             */
984            public int countByUserId(long userId) throws SystemException {
985                    FinderPath finderPath = FINDER_PATH_COUNT_BY_USERID;
986    
987                    Object[] finderArgs = new Object[] { userId };
988    
989                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
990                                    this);
991    
992                    if (count == null) {
993                            StringBundler query = new StringBundler(2);
994    
995                            query.append(_SQL_COUNT_WEBSITE_WHERE);
996    
997                            query.append(_FINDER_COLUMN_USERID_USERID_2);
998    
999                            String sql = query.toString();
1000    
1001                            Session session = null;
1002    
1003                            try {
1004                                    session = openSession();
1005    
1006                                    Query q = session.createQuery(sql);
1007    
1008                                    QueryPos qPos = QueryPos.getInstance(q);
1009    
1010                                    qPos.add(userId);
1011    
1012                                    count = (Long)q.uniqueResult();
1013    
1014                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1015                            }
1016                            catch (Exception e) {
1017                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1018    
1019                                    throw processException(e);
1020                            }
1021                            finally {
1022                                    closeSession(session);
1023                            }
1024                    }
1025    
1026                    return count.intValue();
1027            }
1028    
1029            private static final String _FINDER_COLUMN_USERID_USERID_2 = "website.userId = ?";
1030            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C = new FinderPath(WebsiteModelImpl.ENTITY_CACHE_ENABLED,
1031                            WebsiteModelImpl.FINDER_CACHE_ENABLED, WebsiteImpl.class,
1032                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C",
1033                            new String[] {
1034                                    Long.class.getName(), Long.class.getName(),
1035                                    
1036                            Integer.class.getName(), Integer.class.getName(),
1037                                    OrderByComparator.class.getName()
1038                            });
1039            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C = new FinderPath(WebsiteModelImpl.ENTITY_CACHE_ENABLED,
1040                            WebsiteModelImpl.FINDER_CACHE_ENABLED, WebsiteImpl.class,
1041                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C",
1042                            new String[] { Long.class.getName(), Long.class.getName() },
1043                            WebsiteModelImpl.COMPANYID_COLUMN_BITMASK |
1044                            WebsiteModelImpl.CLASSNAMEID_COLUMN_BITMASK |
1045                            WebsiteModelImpl.CREATEDATE_COLUMN_BITMASK);
1046            public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(WebsiteModelImpl.ENTITY_CACHE_ENABLED,
1047                            WebsiteModelImpl.FINDER_CACHE_ENABLED, Long.class,
1048                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C",
1049                            new String[] { Long.class.getName(), Long.class.getName() });
1050    
1051            /**
1052             * Returns all the websites where companyId = &#63; and classNameId = &#63;.
1053             *
1054             * @param companyId the company ID
1055             * @param classNameId the class name ID
1056             * @return the matching websites
1057             * @throws SystemException if a system exception occurred
1058             */
1059            public List<Website> findByC_C(long companyId, long classNameId)
1060                    throws SystemException {
1061                    return findByC_C(companyId, classNameId, QueryUtil.ALL_POS,
1062                            QueryUtil.ALL_POS, null);
1063            }
1064    
1065            /**
1066             * Returns a range of all the websites where companyId = &#63; and classNameId = &#63;.
1067             *
1068             * <p>
1069             * 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.
1070             * </p>
1071             *
1072             * @param companyId the company ID
1073             * @param classNameId the class name ID
1074             * @param start the lower bound of the range of websites
1075             * @param end the upper bound of the range of websites (not inclusive)
1076             * @return the range of matching websites
1077             * @throws SystemException if a system exception occurred
1078             */
1079            public List<Website> findByC_C(long companyId, long classNameId, int start,
1080                    int end) throws SystemException {
1081                    return findByC_C(companyId, classNameId, start, end, null);
1082            }
1083    
1084            /**
1085             * Returns an ordered range of all the websites where companyId = &#63; and classNameId = &#63;.
1086             *
1087             * <p>
1088             * 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.
1089             * </p>
1090             *
1091             * @param companyId the company ID
1092             * @param classNameId the class name ID
1093             * @param start the lower bound of the range of websites
1094             * @param end the upper bound of the range of websites (not inclusive)
1095             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1096             * @return the ordered range of matching websites
1097             * @throws SystemException if a system exception occurred
1098             */
1099            public List<Website> findByC_C(long companyId, long classNameId, int start,
1100                    int end, OrderByComparator orderByComparator) throws SystemException {
1101                    boolean pagination = true;
1102                    FinderPath finderPath = null;
1103                    Object[] finderArgs = null;
1104    
1105                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1106                                    (orderByComparator == null)) {
1107                            pagination = false;
1108                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C;
1109                            finderArgs = new Object[] { companyId, classNameId };
1110                    }
1111                    else {
1112                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C;
1113                            finderArgs = new Object[] {
1114                                            companyId, classNameId,
1115                                            
1116                                            start, end, orderByComparator
1117                                    };
1118                    }
1119    
1120                    List<Website> list = (List<Website>)FinderCacheUtil.getResult(finderPath,
1121                                    finderArgs, this);
1122    
1123                    if ((list != null) && !list.isEmpty()) {
1124                            for (Website website : list) {
1125                                    if ((companyId != website.getCompanyId()) ||
1126                                                    (classNameId != website.getClassNameId())) {
1127                                            list = null;
1128    
1129                                            break;
1130                                    }
1131                            }
1132                    }
1133    
1134                    if (list == null) {
1135                            StringBundler query = null;
1136    
1137                            if (orderByComparator != null) {
1138                                    query = new StringBundler(4 +
1139                                                    (orderByComparator.getOrderByFields().length * 3));
1140                            }
1141                            else {
1142                                    query = new StringBundler(4);
1143                            }
1144    
1145                            query.append(_SQL_SELECT_WEBSITE_WHERE);
1146    
1147                            query.append(_FINDER_COLUMN_C_C_COMPANYID_2);
1148    
1149                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
1150    
1151                            if (orderByComparator != null) {
1152                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1153                                            orderByComparator);
1154                            }
1155                            else
1156                             if (pagination) {
1157                                    query.append(WebsiteModelImpl.ORDER_BY_JPQL);
1158                            }
1159    
1160                            String sql = query.toString();
1161    
1162                            Session session = null;
1163    
1164                            try {
1165                                    session = openSession();
1166    
1167                                    Query q = session.createQuery(sql);
1168    
1169                                    QueryPos qPos = QueryPos.getInstance(q);
1170    
1171                                    qPos.add(companyId);
1172    
1173                                    qPos.add(classNameId);
1174    
1175                                    if (!pagination) {
1176                                            list = (List<Website>)QueryUtil.list(q, getDialect(),
1177                                                            start, end, false);
1178    
1179                                            Collections.sort(list);
1180    
1181                                            list = new UnmodifiableList<Website>(list);
1182                                    }
1183                                    else {
1184                                            list = (List<Website>)QueryUtil.list(q, getDialect(),
1185                                                            start, end);
1186                                    }
1187    
1188                                    cacheResult(list);
1189    
1190                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1191                            }
1192                            catch (Exception e) {
1193                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1194    
1195                                    throw processException(e);
1196                            }
1197                            finally {
1198                                    closeSession(session);
1199                            }
1200                    }
1201    
1202                    return list;
1203            }
1204    
1205            /**
1206             * Returns the first website in the ordered set where companyId = &#63; and classNameId = &#63;.
1207             *
1208             * @param companyId the company ID
1209             * @param classNameId the class name ID
1210             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1211             * @return the first matching website
1212             * @throws com.liferay.portal.NoSuchWebsiteException if a matching website could not be found
1213             * @throws SystemException if a system exception occurred
1214             */
1215            public Website findByC_C_First(long companyId, long classNameId,
1216                    OrderByComparator orderByComparator)
1217                    throws NoSuchWebsiteException, SystemException {
1218                    Website website = fetchByC_C_First(companyId, classNameId,
1219                                    orderByComparator);
1220    
1221                    if (website != null) {
1222                            return website;
1223                    }
1224    
1225                    StringBundler msg = new StringBundler(6);
1226    
1227                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1228    
1229                    msg.append("companyId=");
1230                    msg.append(companyId);
1231    
1232                    msg.append(", classNameId=");
1233                    msg.append(classNameId);
1234    
1235                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1236    
1237                    throw new NoSuchWebsiteException(msg.toString());
1238            }
1239    
1240            /**
1241             * Returns the first website in the ordered set where companyId = &#63; and classNameId = &#63;.
1242             *
1243             * @param companyId the company ID
1244             * @param classNameId the class name ID
1245             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1246             * @return the first matching website, or <code>null</code> if a matching website could not be found
1247             * @throws SystemException if a system exception occurred
1248             */
1249            public Website fetchByC_C_First(long companyId, long classNameId,
1250                    OrderByComparator orderByComparator) throws SystemException {
1251                    List<Website> list = findByC_C(companyId, classNameId, 0, 1,
1252                                    orderByComparator);
1253    
1254                    if (!list.isEmpty()) {
1255                            return list.get(0);
1256                    }
1257    
1258                    return null;
1259            }
1260    
1261            /**
1262             * Returns the last website in the ordered set where companyId = &#63; and classNameId = &#63;.
1263             *
1264             * @param companyId the company ID
1265             * @param classNameId the class name ID
1266             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1267             * @return the last matching website
1268             * @throws com.liferay.portal.NoSuchWebsiteException if a matching website could not be found
1269             * @throws SystemException if a system exception occurred
1270             */
1271            public Website findByC_C_Last(long companyId, long classNameId,
1272                    OrderByComparator orderByComparator)
1273                    throws NoSuchWebsiteException, SystemException {
1274                    Website website = fetchByC_C_Last(companyId, classNameId,
1275                                    orderByComparator);
1276    
1277                    if (website != null) {
1278                            return website;
1279                    }
1280    
1281                    StringBundler msg = new StringBundler(6);
1282    
1283                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1284    
1285                    msg.append("companyId=");
1286                    msg.append(companyId);
1287    
1288                    msg.append(", classNameId=");
1289                    msg.append(classNameId);
1290    
1291                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1292    
1293                    throw new NoSuchWebsiteException(msg.toString());
1294            }
1295    
1296            /**
1297             * Returns the last website in the ordered set where companyId = &#63; and classNameId = &#63;.
1298             *
1299             * @param companyId the company ID
1300             * @param classNameId the class name ID
1301             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1302             * @return the last matching website, or <code>null</code> if a matching website could not be found
1303             * @throws SystemException if a system exception occurred
1304             */
1305            public Website fetchByC_C_Last(long companyId, long classNameId,
1306                    OrderByComparator orderByComparator) throws SystemException {
1307                    int count = countByC_C(companyId, classNameId);
1308    
1309                    List<Website> list = findByC_C(companyId, classNameId, count - 1,
1310                                    count, orderByComparator);
1311    
1312                    if (!list.isEmpty()) {
1313                            return list.get(0);
1314                    }
1315    
1316                    return null;
1317            }
1318    
1319            /**
1320             * Returns the websites before and after the current website in the ordered set where companyId = &#63; and classNameId = &#63;.
1321             *
1322             * @param websiteId the primary key of the current website
1323             * @param companyId the company ID
1324             * @param classNameId the class name ID
1325             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1326             * @return the previous, current, and next website
1327             * @throws com.liferay.portal.NoSuchWebsiteException if a website with the primary key could not be found
1328             * @throws SystemException if a system exception occurred
1329             */
1330            public Website[] findByC_C_PrevAndNext(long websiteId, long companyId,
1331                    long classNameId, OrderByComparator orderByComparator)
1332                    throws NoSuchWebsiteException, SystemException {
1333                    Website website = findByPrimaryKey(websiteId);
1334    
1335                    Session session = null;
1336    
1337                    try {
1338                            session = openSession();
1339    
1340                            Website[] array = new WebsiteImpl[3];
1341    
1342                            array[0] = getByC_C_PrevAndNext(session, website, companyId,
1343                                            classNameId, orderByComparator, true);
1344    
1345                            array[1] = website;
1346    
1347                            array[2] = getByC_C_PrevAndNext(session, website, companyId,
1348                                            classNameId, orderByComparator, false);
1349    
1350                            return array;
1351                    }
1352                    catch (Exception e) {
1353                            throw processException(e);
1354                    }
1355                    finally {
1356                            closeSession(session);
1357                    }
1358            }
1359    
1360            protected Website getByC_C_PrevAndNext(Session session, Website website,
1361                    long companyId, long classNameId, OrderByComparator orderByComparator,
1362                    boolean previous) {
1363                    StringBundler query = null;
1364    
1365                    if (orderByComparator != null) {
1366                            query = new StringBundler(6 +
1367                                            (orderByComparator.getOrderByFields().length * 6));
1368                    }
1369                    else {
1370                            query = new StringBundler(3);
1371                    }
1372    
1373                    query.append(_SQL_SELECT_WEBSITE_WHERE);
1374    
1375                    query.append(_FINDER_COLUMN_C_C_COMPANYID_2);
1376    
1377                    query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
1378    
1379                    if (orderByComparator != null) {
1380                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1381    
1382                            if (orderByConditionFields.length > 0) {
1383                                    query.append(WHERE_AND);
1384                            }
1385    
1386                            for (int i = 0; i < orderByConditionFields.length; i++) {
1387                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1388                                    query.append(orderByConditionFields[i]);
1389    
1390                                    if ((i + 1) < orderByConditionFields.length) {
1391                                            if (orderByComparator.isAscending() ^ previous) {
1392                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1393                                            }
1394                                            else {
1395                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1396                                            }
1397                                    }
1398                                    else {
1399                                            if (orderByComparator.isAscending() ^ previous) {
1400                                                    query.append(WHERE_GREATER_THAN);
1401                                            }
1402                                            else {
1403                                                    query.append(WHERE_LESSER_THAN);
1404                                            }
1405                                    }
1406                            }
1407    
1408                            query.append(ORDER_BY_CLAUSE);
1409    
1410                            String[] orderByFields = orderByComparator.getOrderByFields();
1411    
1412                            for (int i = 0; i < orderByFields.length; i++) {
1413                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1414                                    query.append(orderByFields[i]);
1415    
1416                                    if ((i + 1) < orderByFields.length) {
1417                                            if (orderByComparator.isAscending() ^ previous) {
1418                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1419                                            }
1420                                            else {
1421                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1422                                            }
1423                                    }
1424                                    else {
1425                                            if (orderByComparator.isAscending() ^ previous) {
1426                                                    query.append(ORDER_BY_ASC);
1427                                            }
1428                                            else {
1429                                                    query.append(ORDER_BY_DESC);
1430                                            }
1431                                    }
1432                            }
1433                    }
1434                    else {
1435                            query.append(WebsiteModelImpl.ORDER_BY_JPQL);
1436                    }
1437    
1438                    String sql = query.toString();
1439    
1440                    Query q = session.createQuery(sql);
1441    
1442                    q.setFirstResult(0);
1443                    q.setMaxResults(2);
1444    
1445                    QueryPos qPos = QueryPos.getInstance(q);
1446    
1447                    qPos.add(companyId);
1448    
1449                    qPos.add(classNameId);
1450    
1451                    if (orderByComparator != null) {
1452                            Object[] values = orderByComparator.getOrderByConditionValues(website);
1453    
1454                            for (Object value : values) {
1455                                    qPos.add(value);
1456                            }
1457                    }
1458    
1459                    List<Website> list = q.list();
1460    
1461                    if (list.size() == 2) {
1462                            return list.get(1);
1463                    }
1464                    else {
1465                            return null;
1466                    }
1467            }
1468    
1469            /**
1470             * Removes all the websites where companyId = &#63; and classNameId = &#63; from the database.
1471             *
1472             * @param companyId the company ID
1473             * @param classNameId the class name ID
1474             * @throws SystemException if a system exception occurred
1475             */
1476            public void removeByC_C(long companyId, long classNameId)
1477                    throws SystemException {
1478                    for (Website website : findByC_C(companyId, classNameId,
1479                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1480                            remove(website);
1481                    }
1482            }
1483    
1484            /**
1485             * Returns the number of websites where companyId = &#63; and classNameId = &#63;.
1486             *
1487             * @param companyId the company ID
1488             * @param classNameId the class name ID
1489             * @return the number of matching websites
1490             * @throws SystemException if a system exception occurred
1491             */
1492            public int countByC_C(long companyId, long classNameId)
1493                    throws SystemException {
1494                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C;
1495    
1496                    Object[] finderArgs = new Object[] { companyId, classNameId };
1497    
1498                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1499                                    this);
1500    
1501                    if (count == null) {
1502                            StringBundler query = new StringBundler(3);
1503    
1504                            query.append(_SQL_COUNT_WEBSITE_WHERE);
1505    
1506                            query.append(_FINDER_COLUMN_C_C_COMPANYID_2);
1507    
1508                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
1509    
1510                            String sql = query.toString();
1511    
1512                            Session session = null;
1513    
1514                            try {
1515                                    session = openSession();
1516    
1517                                    Query q = session.createQuery(sql);
1518    
1519                                    QueryPos qPos = QueryPos.getInstance(q);
1520    
1521                                    qPos.add(companyId);
1522    
1523                                    qPos.add(classNameId);
1524    
1525                                    count = (Long)q.uniqueResult();
1526    
1527                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1528                            }
1529                            catch (Exception e) {
1530                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1531    
1532                                    throw processException(e);
1533                            }
1534                            finally {
1535                                    closeSession(session);
1536                            }
1537                    }
1538    
1539                    return count.intValue();
1540            }
1541    
1542            private static final String _FINDER_COLUMN_C_C_COMPANYID_2 = "website.companyId = ? AND ";
1543            private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "website.classNameId = ?";
1544            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_C = new FinderPath(WebsiteModelImpl.ENTITY_CACHE_ENABLED,
1545                            WebsiteModelImpl.FINDER_CACHE_ENABLED, WebsiteImpl.class,
1546                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C_C",
1547                            new String[] {
1548                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
1549                                    
1550                            Integer.class.getName(), Integer.class.getName(),
1551                                    OrderByComparator.class.getName()
1552                            });
1553            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C = new FinderPath(WebsiteModelImpl.ENTITY_CACHE_ENABLED,
1554                            WebsiteModelImpl.FINDER_CACHE_ENABLED, WebsiteImpl.class,
1555                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C_C",
1556                            new String[] {
1557                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
1558                            },
1559                            WebsiteModelImpl.COMPANYID_COLUMN_BITMASK |
1560                            WebsiteModelImpl.CLASSNAMEID_COLUMN_BITMASK |
1561                            WebsiteModelImpl.CLASSPK_COLUMN_BITMASK |
1562                            WebsiteModelImpl.CREATEDATE_COLUMN_BITMASK);
1563            public static final FinderPath FINDER_PATH_COUNT_BY_C_C_C = new FinderPath(WebsiteModelImpl.ENTITY_CACHE_ENABLED,
1564                            WebsiteModelImpl.FINDER_CACHE_ENABLED, Long.class,
1565                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_C",
1566                            new String[] {
1567                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
1568                            });
1569    
1570            /**
1571             * Returns all the websites where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
1572             *
1573             * @param companyId the company ID
1574             * @param classNameId the class name ID
1575             * @param classPK the class p k
1576             * @return the matching websites
1577             * @throws SystemException if a system exception occurred
1578             */
1579            public List<Website> findByC_C_C(long companyId, long classNameId,
1580                    long classPK) throws SystemException {
1581                    return findByC_C_C(companyId, classNameId, classPK, QueryUtil.ALL_POS,
1582                            QueryUtil.ALL_POS, null);
1583            }
1584    
1585            /**
1586             * Returns a range of all the websites where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
1587             *
1588             * <p>
1589             * 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.
1590             * </p>
1591             *
1592             * @param companyId the company ID
1593             * @param classNameId the class name ID
1594             * @param classPK the class p k
1595             * @param start the lower bound of the range of websites
1596             * @param end the upper bound of the range of websites (not inclusive)
1597             * @return the range of matching websites
1598             * @throws SystemException if a system exception occurred
1599             */
1600            public List<Website> findByC_C_C(long companyId, long classNameId,
1601                    long classPK, int start, int end) throws SystemException {
1602                    return findByC_C_C(companyId, classNameId, classPK, start, end, null);
1603            }
1604    
1605            /**
1606             * Returns an ordered range of all the websites where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
1607             *
1608             * <p>
1609             * 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.
1610             * </p>
1611             *
1612             * @param companyId the company ID
1613             * @param classNameId the class name ID
1614             * @param classPK the class p k
1615             * @param start the lower bound of the range of websites
1616             * @param end the upper bound of the range of websites (not inclusive)
1617             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1618             * @return the ordered range of matching websites
1619             * @throws SystemException if a system exception occurred
1620             */
1621            public List<Website> findByC_C_C(long companyId, long classNameId,
1622                    long classPK, int start, int end, OrderByComparator orderByComparator)
1623                    throws SystemException {
1624                    boolean pagination = true;
1625                    FinderPath finderPath = null;
1626                    Object[] finderArgs = null;
1627    
1628                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1629                                    (orderByComparator == null)) {
1630                            pagination = false;
1631                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C;
1632                            finderArgs = new Object[] { companyId, classNameId, classPK };
1633                    }
1634                    else {
1635                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_C;
1636                            finderArgs = new Object[] {
1637                                            companyId, classNameId, classPK,
1638                                            
1639                                            start, end, orderByComparator
1640                                    };
1641                    }
1642    
1643                    List<Website> list = (List<Website>)FinderCacheUtil.getResult(finderPath,
1644                                    finderArgs, this);
1645    
1646                    if ((list != null) && !list.isEmpty()) {
1647                            for (Website website : list) {
1648                                    if ((companyId != website.getCompanyId()) ||
1649                                                    (classNameId != website.getClassNameId()) ||
1650                                                    (classPK != website.getClassPK())) {
1651                                            list = null;
1652    
1653                                            break;
1654                                    }
1655                            }
1656                    }
1657    
1658                    if (list == null) {
1659                            StringBundler query = null;
1660    
1661                            if (orderByComparator != null) {
1662                                    query = new StringBundler(5 +
1663                                                    (orderByComparator.getOrderByFields().length * 3));
1664                            }
1665                            else {
1666                                    query = new StringBundler(5);
1667                            }
1668    
1669                            query.append(_SQL_SELECT_WEBSITE_WHERE);
1670    
1671                            query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
1672    
1673                            query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
1674    
1675                            query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
1676    
1677                            if (orderByComparator != null) {
1678                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1679                                            orderByComparator);
1680                            }
1681                            else
1682                             if (pagination) {
1683                                    query.append(WebsiteModelImpl.ORDER_BY_JPQL);
1684                            }
1685    
1686                            String sql = query.toString();
1687    
1688                            Session session = null;
1689    
1690                            try {
1691                                    session = openSession();
1692    
1693                                    Query q = session.createQuery(sql);
1694    
1695                                    QueryPos qPos = QueryPos.getInstance(q);
1696    
1697                                    qPos.add(companyId);
1698    
1699                                    qPos.add(classNameId);
1700    
1701                                    qPos.add(classPK);
1702    
1703                                    if (!pagination) {
1704                                            list = (List<Website>)QueryUtil.list(q, getDialect(),
1705                                                            start, end, false);
1706    
1707                                            Collections.sort(list);
1708    
1709                                            list = new UnmodifiableList<Website>(list);
1710                                    }
1711                                    else {
1712                                            list = (List<Website>)QueryUtil.list(q, getDialect(),
1713                                                            start, end);
1714                                    }
1715    
1716                                    cacheResult(list);
1717    
1718                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1719                            }
1720                            catch (Exception e) {
1721                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1722    
1723                                    throw processException(e);
1724                            }
1725                            finally {
1726                                    closeSession(session);
1727                            }
1728                    }
1729    
1730                    return list;
1731            }
1732    
1733            /**
1734             * Returns the first website in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
1735             *
1736             * @param companyId the company ID
1737             * @param classNameId the class name ID
1738             * @param classPK the class p k
1739             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1740             * @return the first matching website
1741             * @throws com.liferay.portal.NoSuchWebsiteException if a matching website could not be found
1742             * @throws SystemException if a system exception occurred
1743             */
1744            public Website findByC_C_C_First(long companyId, long classNameId,
1745                    long classPK, OrderByComparator orderByComparator)
1746                    throws NoSuchWebsiteException, SystemException {
1747                    Website website = fetchByC_C_C_First(companyId, classNameId, classPK,
1748                                    orderByComparator);
1749    
1750                    if (website != null) {
1751                            return website;
1752                    }
1753    
1754                    StringBundler msg = new StringBundler(8);
1755    
1756                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1757    
1758                    msg.append("companyId=");
1759                    msg.append(companyId);
1760    
1761                    msg.append(", classNameId=");
1762                    msg.append(classNameId);
1763    
1764                    msg.append(", classPK=");
1765                    msg.append(classPK);
1766    
1767                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1768    
1769                    throw new NoSuchWebsiteException(msg.toString());
1770            }
1771    
1772            /**
1773             * Returns the first website in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
1774             *
1775             * @param companyId the company ID
1776             * @param classNameId the class name ID
1777             * @param classPK the class p k
1778             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1779             * @return the first matching website, or <code>null</code> if a matching website could not be found
1780             * @throws SystemException if a system exception occurred
1781             */
1782            public Website fetchByC_C_C_First(long companyId, long classNameId,
1783                    long classPK, OrderByComparator orderByComparator)
1784                    throws SystemException {
1785                    List<Website> list = findByC_C_C(companyId, classNameId, classPK, 0, 1,
1786                                    orderByComparator);
1787    
1788                    if (!list.isEmpty()) {
1789                            return list.get(0);
1790                    }
1791    
1792                    return null;
1793            }
1794    
1795            /**
1796             * Returns the last website in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
1797             *
1798             * @param companyId the company ID
1799             * @param classNameId the class name ID
1800             * @param classPK the class p k
1801             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1802             * @return the last matching website
1803             * @throws com.liferay.portal.NoSuchWebsiteException if a matching website could not be found
1804             * @throws SystemException if a system exception occurred
1805             */
1806            public Website findByC_C_C_Last(long companyId, long classNameId,
1807                    long classPK, OrderByComparator orderByComparator)
1808                    throws NoSuchWebsiteException, SystemException {
1809                    Website website = fetchByC_C_C_Last(companyId, classNameId, classPK,
1810                                    orderByComparator);
1811    
1812                    if (website != null) {
1813                            return website;
1814                    }
1815    
1816                    StringBundler msg = new StringBundler(8);
1817    
1818                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1819    
1820                    msg.append("companyId=");
1821                    msg.append(companyId);
1822    
1823                    msg.append(", classNameId=");
1824                    msg.append(classNameId);
1825    
1826                    msg.append(", classPK=");
1827                    msg.append(classPK);
1828    
1829                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1830    
1831                    throw new NoSuchWebsiteException(msg.toString());
1832            }
1833    
1834            /**
1835             * Returns the last website in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
1836             *
1837             * @param companyId the company ID
1838             * @param classNameId the class name ID
1839             * @param classPK the class p k
1840             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1841             * @return the last matching website, or <code>null</code> if a matching website could not be found
1842             * @throws SystemException if a system exception occurred
1843             */
1844            public Website fetchByC_C_C_Last(long companyId, long classNameId,
1845                    long classPK, OrderByComparator orderByComparator)
1846                    throws SystemException {
1847                    int count = countByC_C_C(companyId, classNameId, classPK);
1848    
1849                    List<Website> list = findByC_C_C(companyId, classNameId, classPK,
1850                                    count - 1, count, orderByComparator);
1851    
1852                    if (!list.isEmpty()) {
1853                            return list.get(0);
1854                    }
1855    
1856                    return null;
1857            }
1858    
1859            /**
1860             * Returns the websites before and after the current website in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
1861             *
1862             * @param websiteId the primary key of the current website
1863             * @param companyId the company ID
1864             * @param classNameId the class name ID
1865             * @param classPK the class p k
1866             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1867             * @return the previous, current, and next website
1868             * @throws com.liferay.portal.NoSuchWebsiteException if a website with the primary key could not be found
1869             * @throws SystemException if a system exception occurred
1870             */
1871            public Website[] findByC_C_C_PrevAndNext(long websiteId, long companyId,
1872                    long classNameId, long classPK, OrderByComparator orderByComparator)
1873                    throws NoSuchWebsiteException, SystemException {
1874                    Website website = findByPrimaryKey(websiteId);
1875    
1876                    Session session = null;
1877    
1878                    try {
1879                            session = openSession();
1880    
1881                            Website[] array = new WebsiteImpl[3];
1882    
1883                            array[0] = getByC_C_C_PrevAndNext(session, website, companyId,
1884                                            classNameId, classPK, orderByComparator, true);
1885    
1886                            array[1] = website;
1887    
1888                            array[2] = getByC_C_C_PrevAndNext(session, website, companyId,
1889                                            classNameId, classPK, orderByComparator, false);
1890    
1891                            return array;
1892                    }
1893                    catch (Exception e) {
1894                            throw processException(e);
1895                    }
1896                    finally {
1897                            closeSession(session);
1898                    }
1899            }
1900    
1901            protected Website getByC_C_C_PrevAndNext(Session session, Website website,
1902                    long companyId, long classNameId, long classPK,
1903                    OrderByComparator orderByComparator, boolean previous) {
1904                    StringBundler query = null;
1905    
1906                    if (orderByComparator != null) {
1907                            query = new StringBundler(6 +
1908                                            (orderByComparator.getOrderByFields().length * 6));
1909                    }
1910                    else {
1911                            query = new StringBundler(3);
1912                    }
1913    
1914                    query.append(_SQL_SELECT_WEBSITE_WHERE);
1915    
1916                    query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
1917    
1918                    query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
1919    
1920                    query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
1921    
1922                    if (orderByComparator != null) {
1923                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1924    
1925                            if (orderByConditionFields.length > 0) {
1926                                    query.append(WHERE_AND);
1927                            }
1928    
1929                            for (int i = 0; i < orderByConditionFields.length; i++) {
1930                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1931                                    query.append(orderByConditionFields[i]);
1932    
1933                                    if ((i + 1) < orderByConditionFields.length) {
1934                                            if (orderByComparator.isAscending() ^ previous) {
1935                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1936                                            }
1937                                            else {
1938                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1939                                            }
1940                                    }
1941                                    else {
1942                                            if (orderByComparator.isAscending() ^ previous) {
1943                                                    query.append(WHERE_GREATER_THAN);
1944                                            }
1945                                            else {
1946                                                    query.append(WHERE_LESSER_THAN);
1947                                            }
1948                                    }
1949                            }
1950    
1951                            query.append(ORDER_BY_CLAUSE);
1952    
1953                            String[] orderByFields = orderByComparator.getOrderByFields();
1954    
1955                            for (int i = 0; i < orderByFields.length; i++) {
1956                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1957                                    query.append(orderByFields[i]);
1958    
1959                                    if ((i + 1) < orderByFields.length) {
1960                                            if (orderByComparator.isAscending() ^ previous) {
1961                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1962                                            }
1963                                            else {
1964                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1965                                            }
1966                                    }
1967                                    else {
1968                                            if (orderByComparator.isAscending() ^ previous) {
1969                                                    query.append(ORDER_BY_ASC);
1970                                            }
1971                                            else {
1972                                                    query.append(ORDER_BY_DESC);
1973                                            }
1974                                    }
1975                            }
1976                    }
1977                    else {
1978                            query.append(WebsiteModelImpl.ORDER_BY_JPQL);
1979                    }
1980    
1981                    String sql = query.toString();
1982    
1983                    Query q = session.createQuery(sql);
1984    
1985                    q.setFirstResult(0);
1986                    q.setMaxResults(2);
1987    
1988                    QueryPos qPos = QueryPos.getInstance(q);
1989    
1990                    qPos.add(companyId);
1991    
1992                    qPos.add(classNameId);
1993    
1994                    qPos.add(classPK);
1995    
1996                    if (orderByComparator != null) {
1997                            Object[] values = orderByComparator.getOrderByConditionValues(website);
1998    
1999                            for (Object value : values) {
2000                                    qPos.add(value);
2001                            }
2002                    }
2003    
2004                    List<Website> list = q.list();
2005    
2006                    if (list.size() == 2) {
2007                            return list.get(1);
2008                    }
2009                    else {
2010                            return null;
2011                    }
2012            }
2013    
2014            /**
2015             * Removes all the websites where companyId = &#63; and classNameId = &#63; and classPK = &#63; from the database.
2016             *
2017             * @param companyId the company ID
2018             * @param classNameId the class name ID
2019             * @param classPK the class p k
2020             * @throws SystemException if a system exception occurred
2021             */
2022            public void removeByC_C_C(long companyId, long classNameId, long classPK)
2023                    throws SystemException {
2024                    for (Website website : findByC_C_C(companyId, classNameId, classPK,
2025                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2026                            remove(website);
2027                    }
2028            }
2029    
2030            /**
2031             * Returns the number of websites where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
2032             *
2033             * @param companyId the company ID
2034             * @param classNameId the class name ID
2035             * @param classPK the class p k
2036             * @return the number of matching websites
2037             * @throws SystemException if a system exception occurred
2038             */
2039            public int countByC_C_C(long companyId, long classNameId, long classPK)
2040                    throws SystemException {
2041                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C_C;
2042    
2043                    Object[] finderArgs = new Object[] { companyId, classNameId, classPK };
2044    
2045                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2046                                    this);
2047    
2048                    if (count == null) {
2049                            StringBundler query = new StringBundler(4);
2050    
2051                            query.append(_SQL_COUNT_WEBSITE_WHERE);
2052    
2053                            query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
2054    
2055                            query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
2056    
2057                            query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
2058    
2059                            String sql = query.toString();
2060    
2061                            Session session = null;
2062    
2063                            try {
2064                                    session = openSession();
2065    
2066                                    Query q = session.createQuery(sql);
2067    
2068                                    QueryPos qPos = QueryPos.getInstance(q);
2069    
2070                                    qPos.add(companyId);
2071    
2072                                    qPos.add(classNameId);
2073    
2074                                    qPos.add(classPK);
2075    
2076                                    count = (Long)q.uniqueResult();
2077    
2078                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2079                            }
2080                            catch (Exception e) {
2081                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2082    
2083                                    throw processException(e);
2084                            }
2085                            finally {
2086                                    closeSession(session);
2087                            }
2088                    }
2089    
2090                    return count.intValue();
2091            }
2092    
2093            private static final String _FINDER_COLUMN_C_C_C_COMPANYID_2 = "website.companyId = ? AND ";
2094            private static final String _FINDER_COLUMN_C_C_C_CLASSNAMEID_2 = "website.classNameId = ? AND ";
2095            private static final String _FINDER_COLUMN_C_C_C_CLASSPK_2 = "website.classPK = ?";
2096            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_C_P = new FinderPath(WebsiteModelImpl.ENTITY_CACHE_ENABLED,
2097                            WebsiteModelImpl.FINDER_CACHE_ENABLED, WebsiteImpl.class,
2098                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C_C_P",
2099                            new String[] {
2100                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
2101                                    Boolean.class.getName(),
2102                                    
2103                            Integer.class.getName(), Integer.class.getName(),
2104                                    OrderByComparator.class.getName()
2105                            });
2106            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C_P =
2107                    new FinderPath(WebsiteModelImpl.ENTITY_CACHE_ENABLED,
2108                            WebsiteModelImpl.FINDER_CACHE_ENABLED, WebsiteImpl.class,
2109                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C_C_P",
2110                            new String[] {
2111                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
2112                                    Boolean.class.getName()
2113                            },
2114                            WebsiteModelImpl.COMPANYID_COLUMN_BITMASK |
2115                            WebsiteModelImpl.CLASSNAMEID_COLUMN_BITMASK |
2116                            WebsiteModelImpl.CLASSPK_COLUMN_BITMASK |
2117                            WebsiteModelImpl.PRIMARY_COLUMN_BITMASK |
2118                            WebsiteModelImpl.CREATEDATE_COLUMN_BITMASK);
2119            public static final FinderPath FINDER_PATH_COUNT_BY_C_C_C_P = new FinderPath(WebsiteModelImpl.ENTITY_CACHE_ENABLED,
2120                            WebsiteModelImpl.FINDER_CACHE_ENABLED, Long.class,
2121                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_C_P",
2122                            new String[] {
2123                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
2124                                    Boolean.class.getName()
2125                            });
2126    
2127            /**
2128             * Returns all the websites where companyId = &#63; and classNameId = &#63; and classPK = &#63; and primary = &#63;.
2129             *
2130             * @param companyId the company ID
2131             * @param classNameId the class name ID
2132             * @param classPK the class p k
2133             * @param primary the primary
2134             * @return the matching websites
2135             * @throws SystemException if a system exception occurred
2136             */
2137            public List<Website> findByC_C_C_P(long companyId, long classNameId,
2138                    long classPK, boolean primary) throws SystemException {
2139                    return findByC_C_C_P(companyId, classNameId, classPK, primary,
2140                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2141            }
2142    
2143            /**
2144             * Returns a range of all the websites where companyId = &#63; and classNameId = &#63; and classPK = &#63; and primary = &#63;.
2145             *
2146             * <p>
2147             * 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.
2148             * </p>
2149             *
2150             * @param companyId the company ID
2151             * @param classNameId the class name ID
2152             * @param classPK the class p k
2153             * @param primary the primary
2154             * @param start the lower bound of the range of websites
2155             * @param end the upper bound of the range of websites (not inclusive)
2156             * @return the range of matching websites
2157             * @throws SystemException if a system exception occurred
2158             */
2159            public List<Website> findByC_C_C_P(long companyId, long classNameId,
2160                    long classPK, boolean primary, int start, int end)
2161                    throws SystemException {
2162                    return findByC_C_C_P(companyId, classNameId, classPK, primary, start,
2163                            end, null);
2164            }
2165    
2166            /**
2167             * Returns an ordered range of all the websites where companyId = &#63; and classNameId = &#63; and classPK = &#63; and primary = &#63;.
2168             *
2169             * <p>
2170             * 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.
2171             * </p>
2172             *
2173             * @param companyId the company ID
2174             * @param classNameId the class name ID
2175             * @param classPK the class p k
2176             * @param primary the primary
2177             * @param start the lower bound of the range of websites
2178             * @param end the upper bound of the range of websites (not inclusive)
2179             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2180             * @return the ordered range of matching websites
2181             * @throws SystemException if a system exception occurred
2182             */
2183            public List<Website> findByC_C_C_P(long companyId, long classNameId,
2184                    long classPK, boolean primary, int start, int end,
2185                    OrderByComparator orderByComparator) throws SystemException {
2186                    boolean pagination = true;
2187                    FinderPath finderPath = null;
2188                    Object[] finderArgs = null;
2189    
2190                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2191                                    (orderByComparator == null)) {
2192                            pagination = false;
2193                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C_P;
2194                            finderArgs = new Object[] { companyId, classNameId, classPK, primary };
2195                    }
2196                    else {
2197                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_C_P;
2198                            finderArgs = new Object[] {
2199                                            companyId, classNameId, classPK, primary,
2200                                            
2201                                            start, end, orderByComparator
2202                                    };
2203                    }
2204    
2205                    List<Website> list = (List<Website>)FinderCacheUtil.getResult(finderPath,
2206                                    finderArgs, this);
2207    
2208                    if ((list != null) && !list.isEmpty()) {
2209                            for (Website website : list) {
2210                                    if ((companyId != website.getCompanyId()) ||
2211                                                    (classNameId != website.getClassNameId()) ||
2212                                                    (classPK != website.getClassPK()) ||
2213                                                    (primary != website.getPrimary())) {
2214                                            list = null;
2215    
2216                                            break;
2217                                    }
2218                            }
2219                    }
2220    
2221                    if (list == null) {
2222                            StringBundler query = null;
2223    
2224                            if (orderByComparator != null) {
2225                                    query = new StringBundler(6 +
2226                                                    (orderByComparator.getOrderByFields().length * 3));
2227                            }
2228                            else {
2229                                    query = new StringBundler(6);
2230                            }
2231    
2232                            query.append(_SQL_SELECT_WEBSITE_WHERE);
2233    
2234                            query.append(_FINDER_COLUMN_C_C_C_P_COMPANYID_2);
2235    
2236                            query.append(_FINDER_COLUMN_C_C_C_P_CLASSNAMEID_2);
2237    
2238                            query.append(_FINDER_COLUMN_C_C_C_P_CLASSPK_2);
2239    
2240                            query.append(_FINDER_COLUMN_C_C_C_P_PRIMARY_2);
2241    
2242                            if (orderByComparator != null) {
2243                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2244                                            orderByComparator);
2245                            }
2246                            else
2247                             if (pagination) {
2248                                    query.append(WebsiteModelImpl.ORDER_BY_JPQL);
2249                            }
2250    
2251                            String sql = query.toString();
2252    
2253                            Session session = null;
2254    
2255                            try {
2256                                    session = openSession();
2257    
2258                                    Query q = session.createQuery(sql);
2259    
2260                                    QueryPos qPos = QueryPos.getInstance(q);
2261    
2262                                    qPos.add(companyId);
2263    
2264                                    qPos.add(classNameId);
2265    
2266                                    qPos.add(classPK);
2267    
2268                                    qPos.add(primary);
2269    
2270                                    if (!pagination) {
2271                                            list = (List<Website>)QueryUtil.list(q, getDialect(),
2272                                                            start, end, false);
2273    
2274                                            Collections.sort(list);
2275    
2276                                            list = new UnmodifiableList<Website>(list);
2277                                    }
2278                                    else {
2279                                            list = (List<Website>)QueryUtil.list(q, getDialect(),
2280                                                            start, end);
2281                                    }
2282    
2283                                    cacheResult(list);
2284    
2285                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2286                            }
2287                            catch (Exception e) {
2288                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2289    
2290                                    throw processException(e);
2291                            }
2292                            finally {
2293                                    closeSession(session);
2294                            }
2295                    }
2296    
2297                    return list;
2298            }
2299    
2300            /**
2301             * Returns the first website in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63; and primary = &#63;.
2302             *
2303             * @param companyId the company ID
2304             * @param classNameId the class name ID
2305             * @param classPK the class p k
2306             * @param primary the primary
2307             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2308             * @return the first matching website
2309             * @throws com.liferay.portal.NoSuchWebsiteException if a matching website could not be found
2310             * @throws SystemException if a system exception occurred
2311             */
2312            public Website findByC_C_C_P_First(long companyId, long classNameId,
2313                    long classPK, boolean primary, OrderByComparator orderByComparator)
2314                    throws NoSuchWebsiteException, SystemException {
2315                    Website website = fetchByC_C_C_P_First(companyId, classNameId, classPK,
2316                                    primary, orderByComparator);
2317    
2318                    if (website != null) {
2319                            return website;
2320                    }
2321    
2322                    StringBundler msg = new StringBundler(10);
2323    
2324                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2325    
2326                    msg.append("companyId=");
2327                    msg.append(companyId);
2328    
2329                    msg.append(", classNameId=");
2330                    msg.append(classNameId);
2331    
2332                    msg.append(", classPK=");
2333                    msg.append(classPK);
2334    
2335                    msg.append(", primary=");
2336                    msg.append(primary);
2337    
2338                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2339    
2340                    throw new NoSuchWebsiteException(msg.toString());
2341            }
2342    
2343            /**
2344             * Returns the first website in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63; and primary = &#63;.
2345             *
2346             * @param companyId the company ID
2347             * @param classNameId the class name ID
2348             * @param classPK the class p k
2349             * @param primary the primary
2350             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2351             * @return the first matching website, or <code>null</code> if a matching website could not be found
2352             * @throws SystemException if a system exception occurred
2353             */
2354            public Website fetchByC_C_C_P_First(long companyId, long classNameId,
2355                    long classPK, boolean primary, OrderByComparator orderByComparator)
2356                    throws SystemException {
2357                    List<Website> list = findByC_C_C_P(companyId, classNameId, classPK,
2358                                    primary, 0, 1, orderByComparator);
2359    
2360                    if (!list.isEmpty()) {
2361                            return list.get(0);
2362                    }
2363    
2364                    return null;
2365            }
2366    
2367            /**
2368             * Returns the last website in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63; and primary = &#63;.
2369             *
2370             * @param companyId the company ID
2371             * @param classNameId the class name ID
2372             * @param classPK the class p k
2373             * @param primary the primary
2374             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2375             * @return the last matching website
2376             * @throws com.liferay.portal.NoSuchWebsiteException if a matching website could not be found
2377             * @throws SystemException if a system exception occurred
2378             */
2379            public Website findByC_C_C_P_Last(long companyId, long classNameId,
2380                    long classPK, boolean primary, OrderByComparator orderByComparator)
2381                    throws NoSuchWebsiteException, SystemException {
2382                    Website website = fetchByC_C_C_P_Last(companyId, classNameId, classPK,
2383                                    primary, orderByComparator);
2384    
2385                    if (website != null) {
2386                            return website;
2387                    }
2388    
2389                    StringBundler msg = new StringBundler(10);
2390    
2391                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2392    
2393                    msg.append("companyId=");
2394                    msg.append(companyId);
2395    
2396                    msg.append(", classNameId=");
2397                    msg.append(classNameId);
2398    
2399                    msg.append(", classPK=");
2400                    msg.append(classPK);
2401    
2402                    msg.append(", primary=");
2403                    msg.append(primary);
2404    
2405                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2406    
2407                    throw new NoSuchWebsiteException(msg.toString());
2408            }
2409    
2410            /**
2411             * Returns the last website in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63; and primary = &#63;.
2412             *
2413             * @param companyId the company ID
2414             * @param classNameId the class name ID
2415             * @param classPK the class p k
2416             * @param primary the primary
2417             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2418             * @return the last matching website, or <code>null</code> if a matching website could not be found
2419             * @throws SystemException if a system exception occurred
2420             */
2421            public Website fetchByC_C_C_P_Last(long companyId, long classNameId,
2422                    long classPK, boolean primary, OrderByComparator orderByComparator)
2423                    throws SystemException {
2424                    int count = countByC_C_C_P(companyId, classNameId, classPK, primary);
2425    
2426                    List<Website> list = findByC_C_C_P(companyId, classNameId, classPK,
2427                                    primary, count - 1, count, orderByComparator);
2428    
2429                    if (!list.isEmpty()) {
2430                            return list.get(0);
2431                    }
2432    
2433                    return null;
2434            }
2435    
2436            /**
2437             * 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;.
2438             *
2439             * @param websiteId the primary key of the current website
2440             * @param companyId the company ID
2441             * @param classNameId the class name ID
2442             * @param classPK the class p k
2443             * @param primary the primary
2444             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2445             * @return the previous, current, and next website
2446             * @throws com.liferay.portal.NoSuchWebsiteException if a website with the primary key could not be found
2447             * @throws SystemException if a system exception occurred
2448             */
2449            public Website[] findByC_C_C_P_PrevAndNext(long websiteId, long companyId,
2450                    long classNameId, long classPK, boolean primary,
2451                    OrderByComparator orderByComparator)
2452                    throws NoSuchWebsiteException, SystemException {
2453                    Website website = findByPrimaryKey(websiteId);
2454    
2455                    Session session = null;
2456    
2457                    try {
2458                            session = openSession();
2459    
2460                            Website[] array = new WebsiteImpl[3];
2461    
2462                            array[0] = getByC_C_C_P_PrevAndNext(session, website, companyId,
2463                                            classNameId, classPK, primary, orderByComparator, true);
2464    
2465                            array[1] = website;
2466    
2467                            array[2] = getByC_C_C_P_PrevAndNext(session, website, companyId,
2468                                            classNameId, classPK, primary, orderByComparator, false);
2469    
2470                            return array;
2471                    }
2472                    catch (Exception e) {
2473                            throw processException(e);
2474                    }
2475                    finally {
2476                            closeSession(session);
2477                    }
2478            }
2479    
2480            protected Website getByC_C_C_P_PrevAndNext(Session session,
2481                    Website website, long companyId, long classNameId, long classPK,
2482                    boolean primary, OrderByComparator orderByComparator, boolean previous) {
2483                    StringBundler query = null;
2484    
2485                    if (orderByComparator != null) {
2486                            query = new StringBundler(6 +
2487                                            (orderByComparator.getOrderByFields().length * 6));
2488                    }
2489                    else {
2490                            query = new StringBundler(3);
2491                    }
2492    
2493                    query.append(_SQL_SELECT_WEBSITE_WHERE);
2494    
2495                    query.append(_FINDER_COLUMN_C_C_C_P_COMPANYID_2);
2496    
2497                    query.append(_FINDER_COLUMN_C_C_C_P_CLASSNAMEID_2);
2498    
2499                    query.append(_FINDER_COLUMN_C_C_C_P_CLASSPK_2);
2500    
2501                    query.append(_FINDER_COLUMN_C_C_C_P_PRIMARY_2);
2502    
2503                    if (orderByComparator != null) {
2504                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2505    
2506                            if (orderByConditionFields.length > 0) {
2507                                    query.append(WHERE_AND);
2508                            }
2509    
2510                            for (int i = 0; i < orderByConditionFields.length; i++) {
2511                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2512                                    query.append(orderByConditionFields[i]);
2513    
2514                                    if ((i + 1) < orderByConditionFields.length) {
2515                                            if (orderByComparator.isAscending() ^ previous) {
2516                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2517                                            }
2518                                            else {
2519                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2520                                            }
2521                                    }
2522                                    else {
2523                                            if (orderByComparator.isAscending() ^ previous) {
2524                                                    query.append(WHERE_GREATER_THAN);
2525                                            }
2526                                            else {
2527                                                    query.append(WHERE_LESSER_THAN);
2528                                            }
2529                                    }
2530                            }
2531    
2532                            query.append(ORDER_BY_CLAUSE);
2533    
2534                            String[] orderByFields = orderByComparator.getOrderByFields();
2535    
2536                            for (int i = 0; i < orderByFields.length; i++) {
2537                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2538                                    query.append(orderByFields[i]);
2539    
2540                                    if ((i + 1) < orderByFields.length) {
2541                                            if (orderByComparator.isAscending() ^ previous) {
2542                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2543                                            }
2544                                            else {
2545                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2546                                            }
2547                                    }
2548                                    else {
2549                                            if (orderByComparator.isAscending() ^ previous) {
2550                                                    query.append(ORDER_BY_ASC);
2551                                            }
2552                                            else {
2553                                                    query.append(ORDER_BY_DESC);
2554                                            }
2555                                    }
2556                            }
2557                    }
2558                    else {
2559                            query.append(WebsiteModelImpl.ORDER_BY_JPQL);
2560                    }
2561    
2562                    String sql = query.toString();
2563    
2564                    Query q = session.createQuery(sql);
2565    
2566                    q.setFirstResult(0);
2567                    q.setMaxResults(2);
2568    
2569                    QueryPos qPos = QueryPos.getInstance(q);
2570    
2571                    qPos.add(companyId);
2572    
2573                    qPos.add(classNameId);
2574    
2575                    qPos.add(classPK);
2576    
2577                    qPos.add(primary);
2578    
2579                    if (orderByComparator != null) {
2580                            Object[] values = orderByComparator.getOrderByConditionValues(website);
2581    
2582                            for (Object value : values) {
2583                                    qPos.add(value);
2584                            }
2585                    }
2586    
2587                    List<Website> list = q.list();
2588    
2589                    if (list.size() == 2) {
2590                            return list.get(1);
2591                    }
2592                    else {
2593                            return null;
2594                    }
2595            }
2596    
2597            /**
2598             * Removes all the websites where companyId = &#63; and classNameId = &#63; and classPK = &#63; and primary = &#63; from the database.
2599             *
2600             * @param companyId the company ID
2601             * @param classNameId the class name ID
2602             * @param classPK the class p k
2603             * @param primary the primary
2604             * @throws SystemException if a system exception occurred
2605             */
2606            public void removeByC_C_C_P(long companyId, long classNameId, long classPK,
2607                    boolean primary) throws SystemException {
2608                    for (Website website : findByC_C_C_P(companyId, classNameId, classPK,
2609                                    primary, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2610                            remove(website);
2611                    }
2612            }
2613    
2614            /**
2615             * Returns the number of websites where companyId = &#63; and classNameId = &#63; and classPK = &#63; and primary = &#63;.
2616             *
2617             * @param companyId the company ID
2618             * @param classNameId the class name ID
2619             * @param classPK the class p k
2620             * @param primary the primary
2621             * @return the number of matching websites
2622             * @throws SystemException if a system exception occurred
2623             */
2624            public int countByC_C_C_P(long companyId, long classNameId, long classPK,
2625                    boolean primary) throws SystemException {
2626                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C_C_P;
2627    
2628                    Object[] finderArgs = new Object[] {
2629                                    companyId, classNameId, classPK, primary
2630                            };
2631    
2632                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2633                                    this);
2634    
2635                    if (count == null) {
2636                            StringBundler query = new StringBundler(5);
2637    
2638                            query.append(_SQL_COUNT_WEBSITE_WHERE);
2639    
2640                            query.append(_FINDER_COLUMN_C_C_C_P_COMPANYID_2);
2641    
2642                            query.append(_FINDER_COLUMN_C_C_C_P_CLASSNAMEID_2);
2643    
2644                            query.append(_FINDER_COLUMN_C_C_C_P_CLASSPK_2);
2645    
2646                            query.append(_FINDER_COLUMN_C_C_C_P_PRIMARY_2);
2647    
2648                            String sql = query.toString();
2649    
2650                            Session session = null;
2651    
2652                            try {
2653                                    session = openSession();
2654    
2655                                    Query q = session.createQuery(sql);
2656    
2657                                    QueryPos qPos = QueryPos.getInstance(q);
2658    
2659                                    qPos.add(companyId);
2660    
2661                                    qPos.add(classNameId);
2662    
2663                                    qPos.add(classPK);
2664    
2665                                    qPos.add(primary);
2666    
2667                                    count = (Long)q.uniqueResult();
2668    
2669                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2670                            }
2671                            catch (Exception e) {
2672                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2673    
2674                                    throw processException(e);
2675                            }
2676                            finally {
2677                                    closeSession(session);
2678                            }
2679                    }
2680    
2681                    return count.intValue();
2682            }
2683    
2684            private static final String _FINDER_COLUMN_C_C_C_P_COMPANYID_2 = "website.companyId = ? AND ";
2685            private static final String _FINDER_COLUMN_C_C_C_P_CLASSNAMEID_2 = "website.classNameId = ? AND ";
2686            private static final String _FINDER_COLUMN_C_C_C_P_CLASSPK_2 = "website.classPK = ? AND ";
2687            private static final String _FINDER_COLUMN_C_C_C_P_PRIMARY_2 = "website.primary = ?";
2688    
2689            /**
2690             * Caches the website in the entity cache if it is enabled.
2691             *
2692             * @param website the website
2693             */
2694            public void cacheResult(Website website) {
2695                    EntityCacheUtil.putResult(WebsiteModelImpl.ENTITY_CACHE_ENABLED,
2696                            WebsiteImpl.class, website.getPrimaryKey(), website);
2697    
2698                    website.resetOriginalValues();
2699            }
2700    
2701            /**
2702             * Caches the websites in the entity cache if it is enabled.
2703             *
2704             * @param websites the websites
2705             */
2706            public void cacheResult(List<Website> websites) {
2707                    for (Website website : websites) {
2708                            if (EntityCacheUtil.getResult(
2709                                                    WebsiteModelImpl.ENTITY_CACHE_ENABLED,
2710                                                    WebsiteImpl.class, website.getPrimaryKey()) == null) {
2711                                    cacheResult(website);
2712                            }
2713                            else {
2714                                    website.resetOriginalValues();
2715                            }
2716                    }
2717            }
2718    
2719            /**
2720             * Clears the cache for all websites.
2721             *
2722             * <p>
2723             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
2724             * </p>
2725             */
2726            @Override
2727            public void clearCache() {
2728                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
2729                            CacheRegistryUtil.clear(WebsiteImpl.class.getName());
2730                    }
2731    
2732                    EntityCacheUtil.clearCache(WebsiteImpl.class.getName());
2733    
2734                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
2735                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2736                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2737            }
2738    
2739            /**
2740             * Clears the cache for the website.
2741             *
2742             * <p>
2743             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
2744             * </p>
2745             */
2746            @Override
2747            public void clearCache(Website website) {
2748                    EntityCacheUtil.removeResult(WebsiteModelImpl.ENTITY_CACHE_ENABLED,
2749                            WebsiteImpl.class, website.getPrimaryKey());
2750    
2751                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2752                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2753            }
2754    
2755            @Override
2756            public void clearCache(List<Website> websites) {
2757                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2758                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2759    
2760                    for (Website website : websites) {
2761                            EntityCacheUtil.removeResult(WebsiteModelImpl.ENTITY_CACHE_ENABLED,
2762                                    WebsiteImpl.class, website.getPrimaryKey());
2763                    }
2764            }
2765    
2766            /**
2767             * Creates a new website with the primary key. Does not add the website to the database.
2768             *
2769             * @param websiteId the primary key for the new website
2770             * @return the new website
2771             */
2772            public Website create(long websiteId) {
2773                    Website website = new WebsiteImpl();
2774    
2775                    website.setNew(true);
2776                    website.setPrimaryKey(websiteId);
2777    
2778                    return website;
2779            }
2780    
2781            /**
2782             * Removes the website with the primary key from the database. Also notifies the appropriate model listeners.
2783             *
2784             * @param websiteId the primary key of the website
2785             * @return the website that was removed
2786             * @throws com.liferay.portal.NoSuchWebsiteException if a website with the primary key could not be found
2787             * @throws SystemException if a system exception occurred
2788             */
2789            public Website remove(long websiteId)
2790                    throws NoSuchWebsiteException, SystemException {
2791                    return remove((Serializable)websiteId);
2792            }
2793    
2794            /**
2795             * Removes the website with the primary key from the database. Also notifies the appropriate model listeners.
2796             *
2797             * @param primaryKey the primary key of the website
2798             * @return the website that was removed
2799             * @throws com.liferay.portal.NoSuchWebsiteException if a website with the primary key could not be found
2800             * @throws SystemException if a system exception occurred
2801             */
2802            @Override
2803            public Website remove(Serializable primaryKey)
2804                    throws NoSuchWebsiteException, SystemException {
2805                    Session session = null;
2806    
2807                    try {
2808                            session = openSession();
2809    
2810                            Website website = (Website)session.get(WebsiteImpl.class, primaryKey);
2811    
2812                            if (website == null) {
2813                                    if (_log.isWarnEnabled()) {
2814                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2815                                    }
2816    
2817                                    throw new NoSuchWebsiteException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2818                                            primaryKey);
2819                            }
2820    
2821                            return remove(website);
2822                    }
2823                    catch (NoSuchWebsiteException nsee) {
2824                            throw nsee;
2825                    }
2826                    catch (Exception e) {
2827                            throw processException(e);
2828                    }
2829                    finally {
2830                            closeSession(session);
2831                    }
2832            }
2833    
2834            @Override
2835            protected Website removeImpl(Website website) throws SystemException {
2836                    website = toUnwrappedModel(website);
2837    
2838                    Session session = null;
2839    
2840                    try {
2841                            session = openSession();
2842    
2843                            if (!session.contains(website)) {
2844                                    website = (Website)session.get(WebsiteImpl.class,
2845                                                    website.getPrimaryKeyObj());
2846                            }
2847    
2848                            if (website != null) {
2849                                    session.delete(website);
2850                            }
2851                    }
2852                    catch (Exception e) {
2853                            throw processException(e);
2854                    }
2855                    finally {
2856                            closeSession(session);
2857                    }
2858    
2859                    if (website != null) {
2860                            clearCache(website);
2861                    }
2862    
2863                    return website;
2864            }
2865    
2866            @Override
2867            public Website updateImpl(com.liferay.portal.model.Website website)
2868                    throws SystemException {
2869                    website = toUnwrappedModel(website);
2870    
2871                    boolean isNew = website.isNew();
2872    
2873                    WebsiteModelImpl websiteModelImpl = (WebsiteModelImpl)website;
2874    
2875                    Session session = null;
2876    
2877                    try {
2878                            session = openSession();
2879    
2880                            if (website.isNew()) {
2881                                    session.save(website);
2882    
2883                                    website.setNew(false);
2884                            }
2885                            else {
2886                                    session.merge(website);
2887                            }
2888                    }
2889                    catch (Exception e) {
2890                            throw processException(e);
2891                    }
2892                    finally {
2893                            closeSession(session);
2894                    }
2895    
2896                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2897    
2898                    if (isNew || !WebsiteModelImpl.COLUMN_BITMASK_ENABLED) {
2899                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2900                    }
2901    
2902                    else {
2903                            if ((websiteModelImpl.getColumnBitmask() &
2904                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
2905                                    Object[] args = new Object[] {
2906                                                    websiteModelImpl.getOriginalCompanyId()
2907                                            };
2908    
2909                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
2910                                            args);
2911                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
2912                                            args);
2913    
2914                                    args = new Object[] { websiteModelImpl.getCompanyId() };
2915    
2916                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
2917                                            args);
2918                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
2919                                            args);
2920                            }
2921    
2922                            if ((websiteModelImpl.getColumnBitmask() &
2923                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
2924                                    Object[] args = new Object[] {
2925                                                    websiteModelImpl.getOriginalUserId()
2926                                            };
2927    
2928                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
2929                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
2930                                            args);
2931    
2932                                    args = new Object[] { websiteModelImpl.getUserId() };
2933    
2934                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
2935                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
2936                                            args);
2937                            }
2938    
2939                            if ((websiteModelImpl.getColumnBitmask() &
2940                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C.getColumnBitmask()) != 0) {
2941                                    Object[] args = new Object[] {
2942                                                    websiteModelImpl.getOriginalCompanyId(),
2943                                                    websiteModelImpl.getOriginalClassNameId()
2944                                            };
2945    
2946                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
2947                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
2948                                            args);
2949    
2950                                    args = new Object[] {
2951                                                    websiteModelImpl.getCompanyId(),
2952                                                    websiteModelImpl.getClassNameId()
2953                                            };
2954    
2955                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
2956                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
2957                                            args);
2958                            }
2959    
2960                            if ((websiteModelImpl.getColumnBitmask() &
2961                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C.getColumnBitmask()) != 0) {
2962                                    Object[] args = new Object[] {
2963                                                    websiteModelImpl.getOriginalCompanyId(),
2964                                                    websiteModelImpl.getOriginalClassNameId(),
2965                                                    websiteModelImpl.getOriginalClassPK()
2966                                            };
2967    
2968                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_C, args);
2969                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C,
2970                                            args);
2971    
2972                                    args = new Object[] {
2973                                                    websiteModelImpl.getCompanyId(),
2974                                                    websiteModelImpl.getClassNameId(),
2975                                                    websiteModelImpl.getClassPK()
2976                                            };
2977    
2978                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_C, args);
2979                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C,
2980                                            args);
2981                            }
2982    
2983                            if ((websiteModelImpl.getColumnBitmask() &
2984                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C_P.getColumnBitmask()) != 0) {
2985                                    Object[] args = new Object[] {
2986                                                    websiteModelImpl.getOriginalCompanyId(),
2987                                                    websiteModelImpl.getOriginalClassNameId(),
2988                                                    websiteModelImpl.getOriginalClassPK(),
2989                                                    websiteModelImpl.getOriginalPrimary()
2990                                            };
2991    
2992                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_C_P, args);
2993                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C_P,
2994                                            args);
2995    
2996                                    args = new Object[] {
2997                                                    websiteModelImpl.getCompanyId(),
2998                                                    websiteModelImpl.getClassNameId(),
2999                                                    websiteModelImpl.getClassPK(),
3000                                                    websiteModelImpl.getPrimary()
3001                                            };
3002    
3003                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_C_P, args);
3004                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C_P,
3005                                            args);
3006                            }
3007                    }
3008    
3009                    EntityCacheUtil.putResult(WebsiteModelImpl.ENTITY_CACHE_ENABLED,
3010                            WebsiteImpl.class, website.getPrimaryKey(), website);
3011    
3012                    return website;
3013            }
3014    
3015            protected Website toUnwrappedModel(Website website) {
3016                    if (website instanceof WebsiteImpl) {
3017                            return website;
3018                    }
3019    
3020                    WebsiteImpl websiteImpl = new WebsiteImpl();
3021    
3022                    websiteImpl.setNew(website.isNew());
3023                    websiteImpl.setPrimaryKey(website.getPrimaryKey());
3024    
3025                    websiteImpl.setWebsiteId(website.getWebsiteId());
3026                    websiteImpl.setCompanyId(website.getCompanyId());
3027                    websiteImpl.setUserId(website.getUserId());
3028                    websiteImpl.setUserName(website.getUserName());
3029                    websiteImpl.setCreateDate(website.getCreateDate());
3030                    websiteImpl.setModifiedDate(website.getModifiedDate());
3031                    websiteImpl.setClassNameId(website.getClassNameId());
3032                    websiteImpl.setClassPK(website.getClassPK());
3033                    websiteImpl.setUrl(website.getUrl());
3034                    websiteImpl.setTypeId(website.getTypeId());
3035                    websiteImpl.setPrimary(website.isPrimary());
3036    
3037                    return websiteImpl;
3038            }
3039    
3040            /**
3041             * Returns the website with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
3042             *
3043             * @param primaryKey the primary key of the website
3044             * @return the website
3045             * @throws com.liferay.portal.NoSuchWebsiteException if a website with the primary key could not be found
3046             * @throws SystemException if a system exception occurred
3047             */
3048            @Override
3049            public Website findByPrimaryKey(Serializable primaryKey)
3050                    throws NoSuchWebsiteException, SystemException {
3051                    Website website = fetchByPrimaryKey(primaryKey);
3052    
3053                    if (website == null) {
3054                            if (_log.isWarnEnabled()) {
3055                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
3056                            }
3057    
3058                            throw new NoSuchWebsiteException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
3059                                    primaryKey);
3060                    }
3061    
3062                    return website;
3063            }
3064    
3065            /**
3066             * Returns the website with the primary key or throws a {@link com.liferay.portal.NoSuchWebsiteException} if it could not be found.
3067             *
3068             * @param websiteId the primary key of the website
3069             * @return the website
3070             * @throws com.liferay.portal.NoSuchWebsiteException if a website with the primary key could not be found
3071             * @throws SystemException if a system exception occurred
3072             */
3073            public Website findByPrimaryKey(long websiteId)
3074                    throws NoSuchWebsiteException, SystemException {
3075                    return findByPrimaryKey((Serializable)websiteId);
3076            }
3077    
3078            /**
3079             * Returns the website with the primary key or returns <code>null</code> if it could not be found.
3080             *
3081             * @param primaryKey the primary key of the website
3082             * @return the website, or <code>null</code> if a website with the primary key could not be found
3083             * @throws SystemException if a system exception occurred
3084             */
3085            @Override
3086            public Website fetchByPrimaryKey(Serializable primaryKey)
3087                    throws SystemException {
3088                    Website website = (Website)EntityCacheUtil.getResult(WebsiteModelImpl.ENTITY_CACHE_ENABLED,
3089                                    WebsiteImpl.class, primaryKey);
3090    
3091                    if (website == _nullWebsite) {
3092                            return null;
3093                    }
3094    
3095                    if (website == null) {
3096                            Session session = null;
3097    
3098                            try {
3099                                    session = openSession();
3100    
3101                                    website = (Website)session.get(WebsiteImpl.class, primaryKey);
3102    
3103                                    if (website != null) {
3104                                            cacheResult(website);
3105                                    }
3106                                    else {
3107                                            EntityCacheUtil.putResult(WebsiteModelImpl.ENTITY_CACHE_ENABLED,
3108                                                    WebsiteImpl.class, primaryKey, _nullWebsite);
3109                                    }
3110                            }
3111                            catch (Exception e) {
3112                                    EntityCacheUtil.removeResult(WebsiteModelImpl.ENTITY_CACHE_ENABLED,
3113                                            WebsiteImpl.class, primaryKey);
3114    
3115                                    throw processException(e);
3116                            }
3117                            finally {
3118                                    closeSession(session);
3119                            }
3120                    }
3121    
3122                    return website;
3123            }
3124    
3125            /**
3126             * Returns the website with the primary key or returns <code>null</code> if it could not be found.
3127             *
3128             * @param websiteId the primary key of the website
3129             * @return the website, or <code>null</code> if a website with the primary key could not be found
3130             * @throws SystemException if a system exception occurred
3131             */
3132            public Website fetchByPrimaryKey(long websiteId) throws SystemException {
3133                    return fetchByPrimaryKey((Serializable)websiteId);
3134            }
3135    
3136            /**
3137             * Returns all the websites.
3138             *
3139             * @return the websites
3140             * @throws SystemException if a system exception occurred
3141             */
3142            public List<Website> findAll() throws SystemException {
3143                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3144            }
3145    
3146            /**
3147             * Returns a range of all the websites.
3148             *
3149             * <p>
3150             * 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.
3151             * </p>
3152             *
3153             * @param start the lower bound of the range of websites
3154             * @param end the upper bound of the range of websites (not inclusive)
3155             * @return the range of websites
3156             * @throws SystemException if a system exception occurred
3157             */
3158            public List<Website> findAll(int start, int end) throws SystemException {
3159                    return findAll(start, end, null);
3160            }
3161    
3162            /**
3163             * Returns an ordered range of all the websites.
3164             *
3165             * <p>
3166             * 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.
3167             * </p>
3168             *
3169             * @param start the lower bound of the range of websites
3170             * @param end the upper bound of the range of websites (not inclusive)
3171             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3172             * @return the ordered range of websites
3173             * @throws SystemException if a system exception occurred
3174             */
3175            public List<Website> findAll(int start, int end,
3176                    OrderByComparator orderByComparator) throws SystemException {
3177                    boolean pagination = true;
3178                    FinderPath finderPath = null;
3179                    Object[] finderArgs = null;
3180    
3181                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3182                                    (orderByComparator == null)) {
3183                            pagination = false;
3184                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
3185                            finderArgs = FINDER_ARGS_EMPTY;
3186                    }
3187                    else {
3188                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
3189                            finderArgs = new Object[] { start, end, orderByComparator };
3190                    }
3191    
3192                    List<Website> list = (List<Website>)FinderCacheUtil.getResult(finderPath,
3193                                    finderArgs, this);
3194    
3195                    if (list == null) {
3196                            StringBundler query = null;
3197                            String sql = null;
3198    
3199                            if (orderByComparator != null) {
3200                                    query = new StringBundler(2 +
3201                                                    (orderByComparator.getOrderByFields().length * 3));
3202    
3203                                    query.append(_SQL_SELECT_WEBSITE);
3204    
3205                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3206                                            orderByComparator);
3207    
3208                                    sql = query.toString();
3209                            }
3210                            else {
3211                                    sql = _SQL_SELECT_WEBSITE;
3212    
3213                                    if (pagination) {
3214                                            sql = sql.concat(WebsiteModelImpl.ORDER_BY_JPQL);
3215                                    }
3216                            }
3217    
3218                            Session session = null;
3219    
3220                            try {
3221                                    session = openSession();
3222    
3223                                    Query q = session.createQuery(sql);
3224    
3225                                    if (!pagination) {
3226                                            list = (List<Website>)QueryUtil.list(q, getDialect(),
3227                                                            start, end, false);
3228    
3229                                            Collections.sort(list);
3230    
3231                                            list = new UnmodifiableList<Website>(list);
3232                                    }
3233                                    else {
3234                                            list = (List<Website>)QueryUtil.list(q, getDialect(),
3235                                                            start, end);
3236                                    }
3237    
3238                                    cacheResult(list);
3239    
3240                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
3241                            }
3242                            catch (Exception e) {
3243                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3244    
3245                                    throw processException(e);
3246                            }
3247                            finally {
3248                                    closeSession(session);
3249                            }
3250                    }
3251    
3252                    return list;
3253            }
3254    
3255            /**
3256             * Removes all the websites from the database.
3257             *
3258             * @throws SystemException if a system exception occurred
3259             */
3260            public void removeAll() throws SystemException {
3261                    for (Website website : findAll()) {
3262                            remove(website);
3263                    }
3264            }
3265    
3266            /**
3267             * Returns the number of websites.
3268             *
3269             * @return the number of websites
3270             * @throws SystemException if a system exception occurred
3271             */
3272            public int countAll() throws SystemException {
3273                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
3274                                    FINDER_ARGS_EMPTY, this);
3275    
3276                    if (count == null) {
3277                            Session session = null;
3278    
3279                            try {
3280                                    session = openSession();
3281    
3282                                    Query q = session.createQuery(_SQL_COUNT_WEBSITE);
3283    
3284                                    count = (Long)q.uniqueResult();
3285    
3286                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
3287                                            FINDER_ARGS_EMPTY, count);
3288                            }
3289                            catch (Exception e) {
3290                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
3291                                            FINDER_ARGS_EMPTY);
3292    
3293                                    throw processException(e);
3294                            }
3295                            finally {
3296                                    closeSession(session);
3297                            }
3298                    }
3299    
3300                    return count.intValue();
3301            }
3302    
3303            /**
3304             * Initializes the website persistence.
3305             */
3306            public void afterPropertiesSet() {
3307                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
3308                                            com.liferay.portal.util.PropsUtil.get(
3309                                                    "value.object.listener.com.liferay.portal.model.Website")));
3310    
3311                    if (listenerClassNames.length > 0) {
3312                            try {
3313                                    List<ModelListener<Website>> listenersList = new ArrayList<ModelListener<Website>>();
3314    
3315                                    for (String listenerClassName : listenerClassNames) {
3316                                            listenersList.add((ModelListener<Website>)InstanceFactory.newInstance(
3317                                                            listenerClassName));
3318                                    }
3319    
3320                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
3321                            }
3322                            catch (Exception e) {
3323                                    _log.error(e);
3324                            }
3325                    }
3326            }
3327    
3328            public void destroy() {
3329                    EntityCacheUtil.removeCache(WebsiteImpl.class.getName());
3330                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
3331                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3332                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3333            }
3334    
3335            private static final String _SQL_SELECT_WEBSITE = "SELECT website FROM Website website";
3336            private static final String _SQL_SELECT_WEBSITE_WHERE = "SELECT website FROM Website website WHERE ";
3337            private static final String _SQL_COUNT_WEBSITE = "SELECT COUNT(website) FROM Website website";
3338            private static final String _SQL_COUNT_WEBSITE_WHERE = "SELECT COUNT(website) FROM Website website WHERE ";
3339            private static final String _ORDER_BY_ENTITY_ALIAS = "website.";
3340            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Website exists with the primary key ";
3341            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Website exists with the key {";
3342            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
3343            private static Log _log = LogFactoryUtil.getLog(WebsitePersistenceImpl.class);
3344            private static Website _nullWebsite = new WebsiteImpl() {
3345                            @Override
3346                            public Object clone() {
3347                                    return this;
3348                            }
3349    
3350                            @Override
3351                            public CacheModel<Website> toCacheModel() {
3352                                    return _nullWebsiteCacheModel;
3353                            }
3354                    };
3355    
3356            private static CacheModel<Website> _nullWebsiteCacheModel = new CacheModel<Website>() {
3357                            public Website toEntityModel() {
3358                                    return _nullWebsite;
3359                            }
3360                    };
3361    }