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