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