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