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