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