001    /**
002     * Copyright (c) 2000-present 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.impl;
016    
017    import aQute.bnd.annotation.ProviderType;
018    
019    import com.liferay.portal.NoSuchEmailAddressException;
020    import com.liferay.portal.kernel.bean.BeanReference;
021    import com.liferay.portal.kernel.dao.orm.EntityCache;
022    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
023    import com.liferay.portal.kernel.dao.orm.FinderCache;
024    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
025    import com.liferay.portal.kernel.dao.orm.FinderPath;
026    import com.liferay.portal.kernel.dao.orm.Query;
027    import com.liferay.portal.kernel.dao.orm.QueryPos;
028    import com.liferay.portal.kernel.dao.orm.QueryUtil;
029    import com.liferay.portal.kernel.dao.orm.Session;
030    import com.liferay.portal.kernel.log.Log;
031    import com.liferay.portal.kernel.log.LogFactoryUtil;
032    import com.liferay.portal.kernel.util.OrderByComparator;
033    import com.liferay.portal.kernel.util.SetUtil;
034    import com.liferay.portal.kernel.util.StringBundler;
035    import com.liferay.portal.kernel.util.StringPool;
036    import com.liferay.portal.kernel.util.Validator;
037    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
038    import com.liferay.portal.model.CacheModel;
039    import com.liferay.portal.model.EmailAddress;
040    import com.liferay.portal.model.MVCCModel;
041    import com.liferay.portal.model.impl.EmailAddressImpl;
042    import com.liferay.portal.model.impl.EmailAddressModelImpl;
043    import com.liferay.portal.service.ServiceContext;
044    import com.liferay.portal.service.ServiceContextThreadLocal;
045    import com.liferay.portal.service.persistence.CompanyProvider;
046    import com.liferay.portal.service.persistence.EmailAddressPersistence;
047    
048    import java.io.Serializable;
049    
050    import java.util.Collections;
051    import java.util.Date;
052    import java.util.HashMap;
053    import java.util.HashSet;
054    import java.util.Iterator;
055    import java.util.List;
056    import java.util.Map;
057    import java.util.Set;
058    
059    /**
060     * The persistence implementation for the email address service.
061     *
062     * <p>
063     * Caching information and settings can be found in <code>portal.properties</code>
064     * </p>
065     *
066     * @author Brian Wing Shun Chan
067     * @see EmailAddressPersistence
068     * @see com.liferay.portal.service.persistence.EmailAddressUtil
069     * @generated
070     */
071    @ProviderType
072    public class EmailAddressPersistenceImpl extends BasePersistenceImpl<EmailAddress>
073            implements EmailAddressPersistence {
074            /*
075             * NOTE FOR DEVELOPERS:
076             *
077             * 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.
078             */
079            public static final String FINDER_CLASS_NAME_ENTITY = EmailAddressImpl.class.getName();
080            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
081                    ".List1";
082            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
083                    ".List2";
084            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(EmailAddressModelImpl.ENTITY_CACHE_ENABLED,
085                            EmailAddressModelImpl.FINDER_CACHE_ENABLED, EmailAddressImpl.class,
086                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
087            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(EmailAddressModelImpl.ENTITY_CACHE_ENABLED,
088                            EmailAddressModelImpl.FINDER_CACHE_ENABLED, EmailAddressImpl.class,
089                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
090            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(EmailAddressModelImpl.ENTITY_CACHE_ENABLED,
091                            EmailAddressModelImpl.FINDER_CACHE_ENABLED, Long.class,
092                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
093            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(EmailAddressModelImpl.ENTITY_CACHE_ENABLED,
094                            EmailAddressModelImpl.FINDER_CACHE_ENABLED, EmailAddressImpl.class,
095                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
096                            new String[] {
097                                    String.class.getName(),
098                                    
099                            Integer.class.getName(), Integer.class.getName(),
100                                    OrderByComparator.class.getName()
101                            });
102            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(EmailAddressModelImpl.ENTITY_CACHE_ENABLED,
103                            EmailAddressModelImpl.FINDER_CACHE_ENABLED, EmailAddressImpl.class,
104                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
105                            new String[] { String.class.getName() },
106                            EmailAddressModelImpl.UUID_COLUMN_BITMASK |
107                            EmailAddressModelImpl.CREATEDATE_COLUMN_BITMASK);
108            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(EmailAddressModelImpl.ENTITY_CACHE_ENABLED,
109                            EmailAddressModelImpl.FINDER_CACHE_ENABLED, Long.class,
110                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
111                            new String[] { String.class.getName() });
112    
113            /**
114             * Returns all the email addresses where uuid = &#63;.
115             *
116             * @param uuid the uuid
117             * @return the matching email addresses
118             */
119            @Override
120            public List<EmailAddress> findByUuid(String uuid) {
121                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
122            }
123    
124            /**
125             * Returns a range of all the email addresses where uuid = &#63;.
126             *
127             * <p>
128             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
129             * </p>
130             *
131             * @param uuid the uuid
132             * @param start the lower bound of the range of email addresses
133             * @param end the upper bound of the range of email addresses (not inclusive)
134             * @return the range of matching email addresses
135             */
136            @Override
137            public List<EmailAddress> findByUuid(String uuid, int start, int end) {
138                    return findByUuid(uuid, start, end, null);
139            }
140    
141            /**
142             * Returns an ordered range of all the email addresses where uuid = &#63;.
143             *
144             * <p>
145             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
146             * </p>
147             *
148             * @param uuid the uuid
149             * @param start the lower bound of the range of email addresses
150             * @param end the upper bound of the range of email addresses (not inclusive)
151             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
152             * @return the ordered range of matching email addresses
153             */
154            @Override
155            public List<EmailAddress> findByUuid(String uuid, int start, int end,
156                    OrderByComparator<EmailAddress> orderByComparator) {
157                    return findByUuid(uuid, start, end, orderByComparator, true);
158            }
159    
160            /**
161             * Returns an ordered range of all the email addresses where uuid = &#63;.
162             *
163             * <p>
164             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
165             * </p>
166             *
167             * @param uuid the uuid
168             * @param start the lower bound of the range of email addresses
169             * @param end the upper bound of the range of email addresses (not inclusive)
170             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
171             * @param retrieveFromCache whether to retrieve from the finder cache
172             * @return the ordered range of matching email addresses
173             */
174            @Override
175            public List<EmailAddress> findByUuid(String uuid, int start, int end,
176                    OrderByComparator<EmailAddress> orderByComparator,
177                    boolean retrieveFromCache) {
178                    boolean pagination = true;
179                    FinderPath finderPath = null;
180                    Object[] finderArgs = null;
181    
182                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
183                                    (orderByComparator == null)) {
184                            pagination = false;
185                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
186                            finderArgs = new Object[] { uuid };
187                    }
188                    else {
189                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
190                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
191                    }
192    
193                    List<EmailAddress> list = null;
194    
195                    if (retrieveFromCache) {
196                            list = (List<EmailAddress>)finderCache.getResult(finderPath,
197                                            finderArgs, this);
198    
199                            if ((list != null) && !list.isEmpty()) {
200                                    for (EmailAddress emailAddress : list) {
201                                            if (!Validator.equals(uuid, emailAddress.getUuid())) {
202                                                    list = null;
203    
204                                                    break;
205                                            }
206                                    }
207                            }
208                    }
209    
210                    if (list == null) {
211                            StringBundler query = null;
212    
213                            if (orderByComparator != null) {
214                                    query = new StringBundler(3 +
215                                                    (orderByComparator.getOrderByFields().length * 3));
216                            }
217                            else {
218                                    query = new StringBundler(3);
219                            }
220    
221                            query.append(_SQL_SELECT_EMAILADDRESS_WHERE);
222    
223                            boolean bindUuid = false;
224    
225                            if (uuid == null) {
226                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
227                            }
228                            else if (uuid.equals(StringPool.BLANK)) {
229                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
230                            }
231                            else {
232                                    bindUuid = true;
233    
234                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
235                            }
236    
237                            if (orderByComparator != null) {
238                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
239                                            orderByComparator);
240                            }
241                            else
242                             if (pagination) {
243                                    query.append(EmailAddressModelImpl.ORDER_BY_JPQL);
244                            }
245    
246                            String sql = query.toString();
247    
248                            Session session = null;
249    
250                            try {
251                                    session = openSession();
252    
253                                    Query q = session.createQuery(sql);
254    
255                                    QueryPos qPos = QueryPos.getInstance(q);
256    
257                                    if (bindUuid) {
258                                            qPos.add(uuid);
259                                    }
260    
261                                    if (!pagination) {
262                                            list = (List<EmailAddress>)QueryUtil.list(q, getDialect(),
263                                                            start, end, false);
264    
265                                            Collections.sort(list);
266    
267                                            list = Collections.unmodifiableList(list);
268                                    }
269                                    else {
270                                            list = (List<EmailAddress>)QueryUtil.list(q, getDialect(),
271                                                            start, end);
272                                    }
273    
274                                    cacheResult(list);
275    
276                                    finderCache.putResult(finderPath, finderArgs, list);
277                            }
278                            catch (Exception e) {
279                                    finderCache.removeResult(finderPath, finderArgs);
280    
281                                    throw processException(e);
282                            }
283                            finally {
284                                    closeSession(session);
285                            }
286                    }
287    
288                    return list;
289            }
290    
291            /**
292             * Returns the first email address in the ordered set where uuid = &#63;.
293             *
294             * @param uuid the uuid
295             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
296             * @return the first matching email address
297             * @throws NoSuchEmailAddressException if a matching email address could not be found
298             */
299            @Override
300            public EmailAddress findByUuid_First(String uuid,
301                    OrderByComparator<EmailAddress> orderByComparator)
302                    throws NoSuchEmailAddressException {
303                    EmailAddress emailAddress = fetchByUuid_First(uuid, orderByComparator);
304    
305                    if (emailAddress != null) {
306                            return emailAddress;
307                    }
308    
309                    StringBundler msg = new StringBundler(4);
310    
311                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
312    
313                    msg.append("uuid=");
314                    msg.append(uuid);
315    
316                    msg.append(StringPool.CLOSE_CURLY_BRACE);
317    
318                    throw new NoSuchEmailAddressException(msg.toString());
319            }
320    
321            /**
322             * Returns the first email address in the ordered set where uuid = &#63;.
323             *
324             * @param uuid the uuid
325             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
326             * @return the first matching email address, or <code>null</code> if a matching email address could not be found
327             */
328            @Override
329            public EmailAddress fetchByUuid_First(String uuid,
330                    OrderByComparator<EmailAddress> orderByComparator) {
331                    List<EmailAddress> list = findByUuid(uuid, 0, 1, orderByComparator);
332    
333                    if (!list.isEmpty()) {
334                            return list.get(0);
335                    }
336    
337                    return null;
338            }
339    
340            /**
341             * Returns the last email address in the ordered set where uuid = &#63;.
342             *
343             * @param uuid the uuid
344             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
345             * @return the last matching email address
346             * @throws NoSuchEmailAddressException if a matching email address could not be found
347             */
348            @Override
349            public EmailAddress findByUuid_Last(String uuid,
350                    OrderByComparator<EmailAddress> orderByComparator)
351                    throws NoSuchEmailAddressException {
352                    EmailAddress emailAddress = fetchByUuid_Last(uuid, orderByComparator);
353    
354                    if (emailAddress != null) {
355                            return emailAddress;
356                    }
357    
358                    StringBundler msg = new StringBundler(4);
359    
360                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
361    
362                    msg.append("uuid=");
363                    msg.append(uuid);
364    
365                    msg.append(StringPool.CLOSE_CURLY_BRACE);
366    
367                    throw new NoSuchEmailAddressException(msg.toString());
368            }
369    
370            /**
371             * Returns the last email address in the ordered set where uuid = &#63;.
372             *
373             * @param uuid the uuid
374             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
375             * @return the last matching email address, or <code>null</code> if a matching email address could not be found
376             */
377            @Override
378            public EmailAddress fetchByUuid_Last(String uuid,
379                    OrderByComparator<EmailAddress> orderByComparator) {
380                    int count = countByUuid(uuid);
381    
382                    if (count == 0) {
383                            return null;
384                    }
385    
386                    List<EmailAddress> list = findByUuid(uuid, count - 1, count,
387                                    orderByComparator);
388    
389                    if (!list.isEmpty()) {
390                            return list.get(0);
391                    }
392    
393                    return null;
394            }
395    
396            /**
397             * Returns the email addresses before and after the current email address in the ordered set where uuid = &#63;.
398             *
399             * @param emailAddressId the primary key of the current email address
400             * @param uuid the uuid
401             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
402             * @return the previous, current, and next email address
403             * @throws NoSuchEmailAddressException if a email address with the primary key could not be found
404             */
405            @Override
406            public EmailAddress[] findByUuid_PrevAndNext(long emailAddressId,
407                    String uuid, OrderByComparator<EmailAddress> orderByComparator)
408                    throws NoSuchEmailAddressException {
409                    EmailAddress emailAddress = findByPrimaryKey(emailAddressId);
410    
411                    Session session = null;
412    
413                    try {
414                            session = openSession();
415    
416                            EmailAddress[] array = new EmailAddressImpl[3];
417    
418                            array[0] = getByUuid_PrevAndNext(session, emailAddress, uuid,
419                                            orderByComparator, true);
420    
421                            array[1] = emailAddress;
422    
423                            array[2] = getByUuid_PrevAndNext(session, emailAddress, uuid,
424                                            orderByComparator, false);
425    
426                            return array;
427                    }
428                    catch (Exception e) {
429                            throw processException(e);
430                    }
431                    finally {
432                            closeSession(session);
433                    }
434            }
435    
436            protected EmailAddress getByUuid_PrevAndNext(Session session,
437                    EmailAddress emailAddress, String uuid,
438                    OrderByComparator<EmailAddress> orderByComparator, boolean previous) {
439                    StringBundler query = null;
440    
441                    if (orderByComparator != null) {
442                            query = new StringBundler(6 +
443                                            (orderByComparator.getOrderByFields().length * 6));
444                    }
445                    else {
446                            query = new StringBundler(3);
447                    }
448    
449                    query.append(_SQL_SELECT_EMAILADDRESS_WHERE);
450    
451                    boolean bindUuid = false;
452    
453                    if (uuid == null) {
454                            query.append(_FINDER_COLUMN_UUID_UUID_1);
455                    }
456                    else if (uuid.equals(StringPool.BLANK)) {
457                            query.append(_FINDER_COLUMN_UUID_UUID_3);
458                    }
459                    else {
460                            bindUuid = true;
461    
462                            query.append(_FINDER_COLUMN_UUID_UUID_2);
463                    }
464    
465                    if (orderByComparator != null) {
466                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
467    
468                            if (orderByConditionFields.length > 0) {
469                                    query.append(WHERE_AND);
470                            }
471    
472                            for (int i = 0; i < orderByConditionFields.length; i++) {
473                                    query.append(_ORDER_BY_ENTITY_ALIAS);
474                                    query.append(orderByConditionFields[i]);
475    
476                                    if ((i + 1) < orderByConditionFields.length) {
477                                            if (orderByComparator.isAscending() ^ previous) {
478                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
479                                            }
480                                            else {
481                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
482                                            }
483                                    }
484                                    else {
485                                            if (orderByComparator.isAscending() ^ previous) {
486                                                    query.append(WHERE_GREATER_THAN);
487                                            }
488                                            else {
489                                                    query.append(WHERE_LESSER_THAN);
490                                            }
491                                    }
492                            }
493    
494                            query.append(ORDER_BY_CLAUSE);
495    
496                            String[] orderByFields = orderByComparator.getOrderByFields();
497    
498                            for (int i = 0; i < orderByFields.length; i++) {
499                                    query.append(_ORDER_BY_ENTITY_ALIAS);
500                                    query.append(orderByFields[i]);
501    
502                                    if ((i + 1) < orderByFields.length) {
503                                            if (orderByComparator.isAscending() ^ previous) {
504                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
505                                            }
506                                            else {
507                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
508                                            }
509                                    }
510                                    else {
511                                            if (orderByComparator.isAscending() ^ previous) {
512                                                    query.append(ORDER_BY_ASC);
513                                            }
514                                            else {
515                                                    query.append(ORDER_BY_DESC);
516                                            }
517                                    }
518                            }
519                    }
520                    else {
521                            query.append(EmailAddressModelImpl.ORDER_BY_JPQL);
522                    }
523    
524                    String sql = query.toString();
525    
526                    Query q = session.createQuery(sql);
527    
528                    q.setFirstResult(0);
529                    q.setMaxResults(2);
530    
531                    QueryPos qPos = QueryPos.getInstance(q);
532    
533                    if (bindUuid) {
534                            qPos.add(uuid);
535                    }
536    
537                    if (orderByComparator != null) {
538                            Object[] values = orderByComparator.getOrderByConditionValues(emailAddress);
539    
540                            for (Object value : values) {
541                                    qPos.add(value);
542                            }
543                    }
544    
545                    List<EmailAddress> list = q.list();
546    
547                    if (list.size() == 2) {
548                            return list.get(1);
549                    }
550                    else {
551                            return null;
552                    }
553            }
554    
555            /**
556             * Removes all the email addresses where uuid = &#63; from the database.
557             *
558             * @param uuid the uuid
559             */
560            @Override
561            public void removeByUuid(String uuid) {
562                    for (EmailAddress emailAddress : findByUuid(uuid, QueryUtil.ALL_POS,
563                                    QueryUtil.ALL_POS, null)) {
564                            remove(emailAddress);
565                    }
566            }
567    
568            /**
569             * Returns the number of email addresses where uuid = &#63;.
570             *
571             * @param uuid the uuid
572             * @return the number of matching email addresses
573             */
574            @Override
575            public int countByUuid(String uuid) {
576                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
577    
578                    Object[] finderArgs = new Object[] { uuid };
579    
580                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
581    
582                    if (count == null) {
583                            StringBundler query = new StringBundler(2);
584    
585                            query.append(_SQL_COUNT_EMAILADDRESS_WHERE);
586    
587                            boolean bindUuid = false;
588    
589                            if (uuid == null) {
590                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
591                            }
592                            else if (uuid.equals(StringPool.BLANK)) {
593                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
594                            }
595                            else {
596                                    bindUuid = true;
597    
598                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
599                            }
600    
601                            String sql = query.toString();
602    
603                            Session session = null;
604    
605                            try {
606                                    session = openSession();
607    
608                                    Query q = session.createQuery(sql);
609    
610                                    QueryPos qPos = QueryPos.getInstance(q);
611    
612                                    if (bindUuid) {
613                                            qPos.add(uuid);
614                                    }
615    
616                                    count = (Long)q.uniqueResult();
617    
618                                    finderCache.putResult(finderPath, finderArgs, count);
619                            }
620                            catch (Exception e) {
621                                    finderCache.removeResult(finderPath, finderArgs);
622    
623                                    throw processException(e);
624                            }
625                            finally {
626                                    closeSession(session);
627                            }
628                    }
629    
630                    return count.intValue();
631            }
632    
633            private static final String _FINDER_COLUMN_UUID_UUID_1 = "emailAddress.uuid IS NULL";
634            private static final String _FINDER_COLUMN_UUID_UUID_2 = "emailAddress.uuid = ?";
635            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(emailAddress.uuid IS NULL OR emailAddress.uuid = '')";
636            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(EmailAddressModelImpl.ENTITY_CACHE_ENABLED,
637                            EmailAddressModelImpl.FINDER_CACHE_ENABLED, EmailAddressImpl.class,
638                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
639                            new String[] {
640                                    String.class.getName(), Long.class.getName(),
641                                    
642                            Integer.class.getName(), Integer.class.getName(),
643                                    OrderByComparator.class.getName()
644                            });
645            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
646                    new FinderPath(EmailAddressModelImpl.ENTITY_CACHE_ENABLED,
647                            EmailAddressModelImpl.FINDER_CACHE_ENABLED, EmailAddressImpl.class,
648                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
649                            new String[] { String.class.getName(), Long.class.getName() },
650                            EmailAddressModelImpl.UUID_COLUMN_BITMASK |
651                            EmailAddressModelImpl.COMPANYID_COLUMN_BITMASK |
652                            EmailAddressModelImpl.CREATEDATE_COLUMN_BITMASK);
653            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(EmailAddressModelImpl.ENTITY_CACHE_ENABLED,
654                            EmailAddressModelImpl.FINDER_CACHE_ENABLED, Long.class,
655                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
656                            new String[] { String.class.getName(), Long.class.getName() });
657    
658            /**
659             * Returns all the email addresses where uuid = &#63; and companyId = &#63;.
660             *
661             * @param uuid the uuid
662             * @param companyId the company ID
663             * @return the matching email addresses
664             */
665            @Override
666            public List<EmailAddress> findByUuid_C(String uuid, long companyId) {
667                    return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
668                            QueryUtil.ALL_POS, null);
669            }
670    
671            /**
672             * Returns a range of all the email addresses where uuid = &#63; and companyId = &#63;.
673             *
674             * <p>
675             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
676             * </p>
677             *
678             * @param uuid the uuid
679             * @param companyId the company ID
680             * @param start the lower bound of the range of email addresses
681             * @param end the upper bound of the range of email addresses (not inclusive)
682             * @return the range of matching email addresses
683             */
684            @Override
685            public List<EmailAddress> findByUuid_C(String uuid, long companyId,
686                    int start, int end) {
687                    return findByUuid_C(uuid, companyId, start, end, null);
688            }
689    
690            /**
691             * Returns an ordered range of all the email addresses where uuid = &#63; and companyId = &#63;.
692             *
693             * <p>
694             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
695             * </p>
696             *
697             * @param uuid the uuid
698             * @param companyId the company ID
699             * @param start the lower bound of the range of email addresses
700             * @param end the upper bound of the range of email addresses (not inclusive)
701             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
702             * @return the ordered range of matching email addresses
703             */
704            @Override
705            public List<EmailAddress> findByUuid_C(String uuid, long companyId,
706                    int start, int end, OrderByComparator<EmailAddress> orderByComparator) {
707                    return findByUuid_C(uuid, companyId, start, end, orderByComparator, true);
708            }
709    
710            /**
711             * Returns an ordered range of all the email addresses where uuid = &#63; and companyId = &#63;.
712             *
713             * <p>
714             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
715             * </p>
716             *
717             * @param uuid the uuid
718             * @param companyId the company ID
719             * @param start the lower bound of the range of email addresses
720             * @param end the upper bound of the range of email addresses (not inclusive)
721             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
722             * @param retrieveFromCache whether to retrieve from the finder cache
723             * @return the ordered range of matching email addresses
724             */
725            @Override
726            public List<EmailAddress> findByUuid_C(String uuid, long companyId,
727                    int start, int end, OrderByComparator<EmailAddress> orderByComparator,
728                    boolean retrieveFromCache) {
729                    boolean pagination = true;
730                    FinderPath finderPath = null;
731                    Object[] finderArgs = null;
732    
733                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
734                                    (orderByComparator == null)) {
735                            pagination = false;
736                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
737                            finderArgs = new Object[] { uuid, companyId };
738                    }
739                    else {
740                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
741                            finderArgs = new Object[] {
742                                            uuid, companyId,
743                                            
744                                            start, end, orderByComparator
745                                    };
746                    }
747    
748                    List<EmailAddress> list = null;
749    
750                    if (retrieveFromCache) {
751                            list = (List<EmailAddress>)finderCache.getResult(finderPath,
752                                            finderArgs, this);
753    
754                            if ((list != null) && !list.isEmpty()) {
755                                    for (EmailAddress emailAddress : list) {
756                                            if (!Validator.equals(uuid, emailAddress.getUuid()) ||
757                                                            (companyId != emailAddress.getCompanyId())) {
758                                                    list = null;
759    
760                                                    break;
761                                            }
762                                    }
763                            }
764                    }
765    
766                    if (list == null) {
767                            StringBundler query = null;
768    
769                            if (orderByComparator != null) {
770                                    query = new StringBundler(4 +
771                                                    (orderByComparator.getOrderByFields().length * 3));
772                            }
773                            else {
774                                    query = new StringBundler(4);
775                            }
776    
777                            query.append(_SQL_SELECT_EMAILADDRESS_WHERE);
778    
779                            boolean bindUuid = false;
780    
781                            if (uuid == null) {
782                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
783                            }
784                            else if (uuid.equals(StringPool.BLANK)) {
785                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
786                            }
787                            else {
788                                    bindUuid = true;
789    
790                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
791                            }
792    
793                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
794    
795                            if (orderByComparator != null) {
796                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
797                                            orderByComparator);
798                            }
799                            else
800                             if (pagination) {
801                                    query.append(EmailAddressModelImpl.ORDER_BY_JPQL);
802                            }
803    
804                            String sql = query.toString();
805    
806                            Session session = null;
807    
808                            try {
809                                    session = openSession();
810    
811                                    Query q = session.createQuery(sql);
812    
813                                    QueryPos qPos = QueryPos.getInstance(q);
814    
815                                    if (bindUuid) {
816                                            qPos.add(uuid);
817                                    }
818    
819                                    qPos.add(companyId);
820    
821                                    if (!pagination) {
822                                            list = (List<EmailAddress>)QueryUtil.list(q, getDialect(),
823                                                            start, end, false);
824    
825                                            Collections.sort(list);
826    
827                                            list = Collections.unmodifiableList(list);
828                                    }
829                                    else {
830                                            list = (List<EmailAddress>)QueryUtil.list(q, getDialect(),
831                                                            start, end);
832                                    }
833    
834                                    cacheResult(list);
835    
836                                    finderCache.putResult(finderPath, finderArgs, list);
837                            }
838                            catch (Exception e) {
839                                    finderCache.removeResult(finderPath, finderArgs);
840    
841                                    throw processException(e);
842                            }
843                            finally {
844                                    closeSession(session);
845                            }
846                    }
847    
848                    return list;
849            }
850    
851            /**
852             * Returns the first email address in the ordered set where uuid = &#63; and companyId = &#63;.
853             *
854             * @param uuid the uuid
855             * @param companyId the company ID
856             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
857             * @return the first matching email address
858             * @throws NoSuchEmailAddressException if a matching email address could not be found
859             */
860            @Override
861            public EmailAddress findByUuid_C_First(String uuid, long companyId,
862                    OrderByComparator<EmailAddress> orderByComparator)
863                    throws NoSuchEmailAddressException {
864                    EmailAddress emailAddress = fetchByUuid_C_First(uuid, companyId,
865                                    orderByComparator);
866    
867                    if (emailAddress != null) {
868                            return emailAddress;
869                    }
870    
871                    StringBundler msg = new StringBundler(6);
872    
873                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
874    
875                    msg.append("uuid=");
876                    msg.append(uuid);
877    
878                    msg.append(", companyId=");
879                    msg.append(companyId);
880    
881                    msg.append(StringPool.CLOSE_CURLY_BRACE);
882    
883                    throw new NoSuchEmailAddressException(msg.toString());
884            }
885    
886            /**
887             * Returns the first email address in the ordered set where uuid = &#63; and companyId = &#63;.
888             *
889             * @param uuid the uuid
890             * @param companyId the company ID
891             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
892             * @return the first matching email address, or <code>null</code> if a matching email address could not be found
893             */
894            @Override
895            public EmailAddress fetchByUuid_C_First(String uuid, long companyId,
896                    OrderByComparator<EmailAddress> orderByComparator) {
897                    List<EmailAddress> list = findByUuid_C(uuid, companyId, 0, 1,
898                                    orderByComparator);
899    
900                    if (!list.isEmpty()) {
901                            return list.get(0);
902                    }
903    
904                    return null;
905            }
906    
907            /**
908             * Returns the last email address in the ordered set where uuid = &#63; and companyId = &#63;.
909             *
910             * @param uuid the uuid
911             * @param companyId the company ID
912             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
913             * @return the last matching email address
914             * @throws NoSuchEmailAddressException if a matching email address could not be found
915             */
916            @Override
917            public EmailAddress findByUuid_C_Last(String uuid, long companyId,
918                    OrderByComparator<EmailAddress> orderByComparator)
919                    throws NoSuchEmailAddressException {
920                    EmailAddress emailAddress = fetchByUuid_C_Last(uuid, companyId,
921                                    orderByComparator);
922    
923                    if (emailAddress != null) {
924                            return emailAddress;
925                    }
926    
927                    StringBundler msg = new StringBundler(6);
928    
929                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
930    
931                    msg.append("uuid=");
932                    msg.append(uuid);
933    
934                    msg.append(", companyId=");
935                    msg.append(companyId);
936    
937                    msg.append(StringPool.CLOSE_CURLY_BRACE);
938    
939                    throw new NoSuchEmailAddressException(msg.toString());
940            }
941    
942            /**
943             * Returns the last email address in the ordered set where uuid = &#63; and companyId = &#63;.
944             *
945             * @param uuid the uuid
946             * @param companyId the company ID
947             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
948             * @return the last matching email address, or <code>null</code> if a matching email address could not be found
949             */
950            @Override
951            public EmailAddress fetchByUuid_C_Last(String uuid, long companyId,
952                    OrderByComparator<EmailAddress> orderByComparator) {
953                    int count = countByUuid_C(uuid, companyId);
954    
955                    if (count == 0) {
956                            return null;
957                    }
958    
959                    List<EmailAddress> list = findByUuid_C(uuid, companyId, count - 1,
960                                    count, orderByComparator);
961    
962                    if (!list.isEmpty()) {
963                            return list.get(0);
964                    }
965    
966                    return null;
967            }
968    
969            /**
970             * Returns the email addresses before and after the current email address in the ordered set where uuid = &#63; and companyId = &#63;.
971             *
972             * @param emailAddressId the primary key of the current email address
973             * @param uuid the uuid
974             * @param companyId the company ID
975             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
976             * @return the previous, current, and next email address
977             * @throws NoSuchEmailAddressException if a email address with the primary key could not be found
978             */
979            @Override
980            public EmailAddress[] findByUuid_C_PrevAndNext(long emailAddressId,
981                    String uuid, long companyId,
982                    OrderByComparator<EmailAddress> orderByComparator)
983                    throws NoSuchEmailAddressException {
984                    EmailAddress emailAddress = findByPrimaryKey(emailAddressId);
985    
986                    Session session = null;
987    
988                    try {
989                            session = openSession();
990    
991                            EmailAddress[] array = new EmailAddressImpl[3];
992    
993                            array[0] = getByUuid_C_PrevAndNext(session, emailAddress, uuid,
994                                            companyId, orderByComparator, true);
995    
996                            array[1] = emailAddress;
997    
998                            array[2] = getByUuid_C_PrevAndNext(session, emailAddress, uuid,
999                                            companyId, orderByComparator, false);
1000    
1001                            return array;
1002                    }
1003                    catch (Exception e) {
1004                            throw processException(e);
1005                    }
1006                    finally {
1007                            closeSession(session);
1008                    }
1009            }
1010    
1011            protected EmailAddress getByUuid_C_PrevAndNext(Session session,
1012                    EmailAddress emailAddress, String uuid, long companyId,
1013                    OrderByComparator<EmailAddress> orderByComparator, boolean previous) {
1014                    StringBundler query = null;
1015    
1016                    if (orderByComparator != null) {
1017                            query = new StringBundler(6 +
1018                                            (orderByComparator.getOrderByFields().length * 6));
1019                    }
1020                    else {
1021                            query = new StringBundler(3);
1022                    }
1023    
1024                    query.append(_SQL_SELECT_EMAILADDRESS_WHERE);
1025    
1026                    boolean bindUuid = false;
1027    
1028                    if (uuid == null) {
1029                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1030                    }
1031                    else if (uuid.equals(StringPool.BLANK)) {
1032                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1033                    }
1034                    else {
1035                            bindUuid = true;
1036    
1037                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1038                    }
1039    
1040                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1041    
1042                    if (orderByComparator != null) {
1043                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1044    
1045                            if (orderByConditionFields.length > 0) {
1046                                    query.append(WHERE_AND);
1047                            }
1048    
1049                            for (int i = 0; i < orderByConditionFields.length; i++) {
1050                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1051                                    query.append(orderByConditionFields[i]);
1052    
1053                                    if ((i + 1) < orderByConditionFields.length) {
1054                                            if (orderByComparator.isAscending() ^ previous) {
1055                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1056                                            }
1057                                            else {
1058                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1059                                            }
1060                                    }
1061                                    else {
1062                                            if (orderByComparator.isAscending() ^ previous) {
1063                                                    query.append(WHERE_GREATER_THAN);
1064                                            }
1065                                            else {
1066                                                    query.append(WHERE_LESSER_THAN);
1067                                            }
1068                                    }
1069                            }
1070    
1071                            query.append(ORDER_BY_CLAUSE);
1072    
1073                            String[] orderByFields = orderByComparator.getOrderByFields();
1074    
1075                            for (int i = 0; i < orderByFields.length; i++) {
1076                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1077                                    query.append(orderByFields[i]);
1078    
1079                                    if ((i + 1) < orderByFields.length) {
1080                                            if (orderByComparator.isAscending() ^ previous) {
1081                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1082                                            }
1083                                            else {
1084                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1085                                            }
1086                                    }
1087                                    else {
1088                                            if (orderByComparator.isAscending() ^ previous) {
1089                                                    query.append(ORDER_BY_ASC);
1090                                            }
1091                                            else {
1092                                                    query.append(ORDER_BY_DESC);
1093                                            }
1094                                    }
1095                            }
1096                    }
1097                    else {
1098                            query.append(EmailAddressModelImpl.ORDER_BY_JPQL);
1099                    }
1100    
1101                    String sql = query.toString();
1102    
1103                    Query q = session.createQuery(sql);
1104    
1105                    q.setFirstResult(0);
1106                    q.setMaxResults(2);
1107    
1108                    QueryPos qPos = QueryPos.getInstance(q);
1109    
1110                    if (bindUuid) {
1111                            qPos.add(uuid);
1112                    }
1113    
1114                    qPos.add(companyId);
1115    
1116                    if (orderByComparator != null) {
1117                            Object[] values = orderByComparator.getOrderByConditionValues(emailAddress);
1118    
1119                            for (Object value : values) {
1120                                    qPos.add(value);
1121                            }
1122                    }
1123    
1124                    List<EmailAddress> list = q.list();
1125    
1126                    if (list.size() == 2) {
1127                            return list.get(1);
1128                    }
1129                    else {
1130                            return null;
1131                    }
1132            }
1133    
1134            /**
1135             * Removes all the email addresses where uuid = &#63; and companyId = &#63; from the database.
1136             *
1137             * @param uuid the uuid
1138             * @param companyId the company ID
1139             */
1140            @Override
1141            public void removeByUuid_C(String uuid, long companyId) {
1142                    for (EmailAddress emailAddress : findByUuid_C(uuid, companyId,
1143                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1144                            remove(emailAddress);
1145                    }
1146            }
1147    
1148            /**
1149             * Returns the number of email addresses where uuid = &#63; and companyId = &#63;.
1150             *
1151             * @param uuid the uuid
1152             * @param companyId the company ID
1153             * @return the number of matching email addresses
1154             */
1155            @Override
1156            public int countByUuid_C(String uuid, long companyId) {
1157                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1158    
1159                    Object[] finderArgs = new Object[] { uuid, companyId };
1160    
1161                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1162    
1163                    if (count == null) {
1164                            StringBundler query = new StringBundler(3);
1165    
1166                            query.append(_SQL_COUNT_EMAILADDRESS_WHERE);
1167    
1168                            boolean bindUuid = false;
1169    
1170                            if (uuid == null) {
1171                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1172                            }
1173                            else if (uuid.equals(StringPool.BLANK)) {
1174                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1175                            }
1176                            else {
1177                                    bindUuid = true;
1178    
1179                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1180                            }
1181    
1182                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1183    
1184                            String sql = query.toString();
1185    
1186                            Session session = null;
1187    
1188                            try {
1189                                    session = openSession();
1190    
1191                                    Query q = session.createQuery(sql);
1192    
1193                                    QueryPos qPos = QueryPos.getInstance(q);
1194    
1195                                    if (bindUuid) {
1196                                            qPos.add(uuid);
1197                                    }
1198    
1199                                    qPos.add(companyId);
1200    
1201                                    count = (Long)q.uniqueResult();
1202    
1203                                    finderCache.putResult(finderPath, finderArgs, count);
1204                            }
1205                            catch (Exception e) {
1206                                    finderCache.removeResult(finderPath, finderArgs);
1207    
1208                                    throw processException(e);
1209                            }
1210                            finally {
1211                                    closeSession(session);
1212                            }
1213                    }
1214    
1215                    return count.intValue();
1216            }
1217    
1218            private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "emailAddress.uuid IS NULL AND ";
1219            private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "emailAddress.uuid = ? AND ";
1220            private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(emailAddress.uuid IS NULL OR emailAddress.uuid = '') AND ";
1221            private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "emailAddress.companyId = ?";
1222            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
1223                    new FinderPath(EmailAddressModelImpl.ENTITY_CACHE_ENABLED,
1224                            EmailAddressModelImpl.FINDER_CACHE_ENABLED, EmailAddressImpl.class,
1225                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
1226                            new String[] {
1227                                    Long.class.getName(),
1228                                    
1229                            Integer.class.getName(), Integer.class.getName(),
1230                                    OrderByComparator.class.getName()
1231                            });
1232            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
1233                    new FinderPath(EmailAddressModelImpl.ENTITY_CACHE_ENABLED,
1234                            EmailAddressModelImpl.FINDER_CACHE_ENABLED, EmailAddressImpl.class,
1235                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
1236                            new String[] { Long.class.getName() },
1237                            EmailAddressModelImpl.COMPANYID_COLUMN_BITMASK |
1238                            EmailAddressModelImpl.CREATEDATE_COLUMN_BITMASK);
1239            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(EmailAddressModelImpl.ENTITY_CACHE_ENABLED,
1240                            EmailAddressModelImpl.FINDER_CACHE_ENABLED, Long.class,
1241                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
1242                            new String[] { Long.class.getName() });
1243    
1244            /**
1245             * Returns all the email addresses where companyId = &#63;.
1246             *
1247             * @param companyId the company ID
1248             * @return the matching email addresses
1249             */
1250            @Override
1251            public List<EmailAddress> findByCompanyId(long companyId) {
1252                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1253                            null);
1254            }
1255    
1256            /**
1257             * Returns a range of all the email addresses where companyId = &#63;.
1258             *
1259             * <p>
1260             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
1261             * </p>
1262             *
1263             * @param companyId the company ID
1264             * @param start the lower bound of the range of email addresses
1265             * @param end the upper bound of the range of email addresses (not inclusive)
1266             * @return the range of matching email addresses
1267             */
1268            @Override
1269            public List<EmailAddress> findByCompanyId(long companyId, int start, int end) {
1270                    return findByCompanyId(companyId, start, end, null);
1271            }
1272    
1273            /**
1274             * Returns an ordered range of all the email addresses where companyId = &#63;.
1275             *
1276             * <p>
1277             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
1278             * </p>
1279             *
1280             * @param companyId the company ID
1281             * @param start the lower bound of the range of email addresses
1282             * @param end the upper bound of the range of email addresses (not inclusive)
1283             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1284             * @return the ordered range of matching email addresses
1285             */
1286            @Override
1287            public List<EmailAddress> findByCompanyId(long companyId, int start,
1288                    int end, OrderByComparator<EmailAddress> orderByComparator) {
1289                    return findByCompanyId(companyId, start, end, orderByComparator, true);
1290            }
1291    
1292            /**
1293             * Returns an ordered range of all the email addresses where companyId = &#63;.
1294             *
1295             * <p>
1296             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
1297             * </p>
1298             *
1299             * @param companyId the company ID
1300             * @param start the lower bound of the range of email addresses
1301             * @param end the upper bound of the range of email addresses (not inclusive)
1302             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1303             * @param retrieveFromCache whether to retrieve from the finder cache
1304             * @return the ordered range of matching email addresses
1305             */
1306            @Override
1307            public List<EmailAddress> findByCompanyId(long companyId, int start,
1308                    int end, OrderByComparator<EmailAddress> orderByComparator,
1309                    boolean retrieveFromCache) {
1310                    boolean pagination = true;
1311                    FinderPath finderPath = null;
1312                    Object[] finderArgs = null;
1313    
1314                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1315                                    (orderByComparator == null)) {
1316                            pagination = false;
1317                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
1318                            finderArgs = new Object[] { companyId };
1319                    }
1320                    else {
1321                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
1322                            finderArgs = new Object[] { companyId, start, end, orderByComparator };
1323                    }
1324    
1325                    List<EmailAddress> list = null;
1326    
1327                    if (retrieveFromCache) {
1328                            list = (List<EmailAddress>)finderCache.getResult(finderPath,
1329                                            finderArgs, this);
1330    
1331                            if ((list != null) && !list.isEmpty()) {
1332                                    for (EmailAddress emailAddress : list) {
1333                                            if ((companyId != emailAddress.getCompanyId())) {
1334                                                    list = null;
1335    
1336                                                    break;
1337                                            }
1338                                    }
1339                            }
1340                    }
1341    
1342                    if (list == null) {
1343                            StringBundler query = null;
1344    
1345                            if (orderByComparator != null) {
1346                                    query = new StringBundler(3 +
1347                                                    (orderByComparator.getOrderByFields().length * 3));
1348                            }
1349                            else {
1350                                    query = new StringBundler(3);
1351                            }
1352    
1353                            query.append(_SQL_SELECT_EMAILADDRESS_WHERE);
1354    
1355                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1356    
1357                            if (orderByComparator != null) {
1358                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1359                                            orderByComparator);
1360                            }
1361                            else
1362                             if (pagination) {
1363                                    query.append(EmailAddressModelImpl.ORDER_BY_JPQL);
1364                            }
1365    
1366                            String sql = query.toString();
1367    
1368                            Session session = null;
1369    
1370                            try {
1371                                    session = openSession();
1372    
1373                                    Query q = session.createQuery(sql);
1374    
1375                                    QueryPos qPos = QueryPos.getInstance(q);
1376    
1377                                    qPos.add(companyId);
1378    
1379                                    if (!pagination) {
1380                                            list = (List<EmailAddress>)QueryUtil.list(q, getDialect(),
1381                                                            start, end, false);
1382    
1383                                            Collections.sort(list);
1384    
1385                                            list = Collections.unmodifiableList(list);
1386                                    }
1387                                    else {
1388                                            list = (List<EmailAddress>)QueryUtil.list(q, getDialect(),
1389                                                            start, end);
1390                                    }
1391    
1392                                    cacheResult(list);
1393    
1394                                    finderCache.putResult(finderPath, finderArgs, list);
1395                            }
1396                            catch (Exception e) {
1397                                    finderCache.removeResult(finderPath, finderArgs);
1398    
1399                                    throw processException(e);
1400                            }
1401                            finally {
1402                                    closeSession(session);
1403                            }
1404                    }
1405    
1406                    return list;
1407            }
1408    
1409            /**
1410             * Returns the first email address in the ordered set where companyId = &#63;.
1411             *
1412             * @param companyId the company ID
1413             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1414             * @return the first matching email address
1415             * @throws NoSuchEmailAddressException if a matching email address could not be found
1416             */
1417            @Override
1418            public EmailAddress findByCompanyId_First(long companyId,
1419                    OrderByComparator<EmailAddress> orderByComparator)
1420                    throws NoSuchEmailAddressException {
1421                    EmailAddress emailAddress = fetchByCompanyId_First(companyId,
1422                                    orderByComparator);
1423    
1424                    if (emailAddress != null) {
1425                            return emailAddress;
1426                    }
1427    
1428                    StringBundler msg = new StringBundler(4);
1429    
1430                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1431    
1432                    msg.append("companyId=");
1433                    msg.append(companyId);
1434    
1435                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1436    
1437                    throw new NoSuchEmailAddressException(msg.toString());
1438            }
1439    
1440            /**
1441             * Returns the first email address in the ordered set where companyId = &#63;.
1442             *
1443             * @param companyId the company ID
1444             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1445             * @return the first matching email address, or <code>null</code> if a matching email address could not be found
1446             */
1447            @Override
1448            public EmailAddress fetchByCompanyId_First(long companyId,
1449                    OrderByComparator<EmailAddress> orderByComparator) {
1450                    List<EmailAddress> list = findByCompanyId(companyId, 0, 1,
1451                                    orderByComparator);
1452    
1453                    if (!list.isEmpty()) {
1454                            return list.get(0);
1455                    }
1456    
1457                    return null;
1458            }
1459    
1460            /**
1461             * Returns the last email address in the ordered set where companyId = &#63;.
1462             *
1463             * @param companyId the company ID
1464             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1465             * @return the last matching email address
1466             * @throws NoSuchEmailAddressException if a matching email address could not be found
1467             */
1468            @Override
1469            public EmailAddress findByCompanyId_Last(long companyId,
1470                    OrderByComparator<EmailAddress> orderByComparator)
1471                    throws NoSuchEmailAddressException {
1472                    EmailAddress emailAddress = fetchByCompanyId_Last(companyId,
1473                                    orderByComparator);
1474    
1475                    if (emailAddress != null) {
1476                            return emailAddress;
1477                    }
1478    
1479                    StringBundler msg = new StringBundler(4);
1480    
1481                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1482    
1483                    msg.append("companyId=");
1484                    msg.append(companyId);
1485    
1486                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1487    
1488                    throw new NoSuchEmailAddressException(msg.toString());
1489            }
1490    
1491            /**
1492             * Returns the last email address in the ordered set where companyId = &#63;.
1493             *
1494             * @param companyId the company ID
1495             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1496             * @return the last matching email address, or <code>null</code> if a matching email address could not be found
1497             */
1498            @Override
1499            public EmailAddress fetchByCompanyId_Last(long companyId,
1500                    OrderByComparator<EmailAddress> orderByComparator) {
1501                    int count = countByCompanyId(companyId);
1502    
1503                    if (count == 0) {
1504                            return null;
1505                    }
1506    
1507                    List<EmailAddress> list = findByCompanyId(companyId, count - 1, count,
1508                                    orderByComparator);
1509    
1510                    if (!list.isEmpty()) {
1511                            return list.get(0);
1512                    }
1513    
1514                    return null;
1515            }
1516    
1517            /**
1518             * Returns the email addresses before and after the current email address in the ordered set where companyId = &#63;.
1519             *
1520             * @param emailAddressId the primary key of the current email address
1521             * @param companyId the company ID
1522             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1523             * @return the previous, current, and next email address
1524             * @throws NoSuchEmailAddressException if a email address with the primary key could not be found
1525             */
1526            @Override
1527            public EmailAddress[] findByCompanyId_PrevAndNext(long emailAddressId,
1528                    long companyId, OrderByComparator<EmailAddress> orderByComparator)
1529                    throws NoSuchEmailAddressException {
1530                    EmailAddress emailAddress = findByPrimaryKey(emailAddressId);
1531    
1532                    Session session = null;
1533    
1534                    try {
1535                            session = openSession();
1536    
1537                            EmailAddress[] array = new EmailAddressImpl[3];
1538    
1539                            array[0] = getByCompanyId_PrevAndNext(session, emailAddress,
1540                                            companyId, orderByComparator, true);
1541    
1542                            array[1] = emailAddress;
1543    
1544                            array[2] = getByCompanyId_PrevAndNext(session, emailAddress,
1545                                            companyId, orderByComparator, false);
1546    
1547                            return array;
1548                    }
1549                    catch (Exception e) {
1550                            throw processException(e);
1551                    }
1552                    finally {
1553                            closeSession(session);
1554                    }
1555            }
1556    
1557            protected EmailAddress getByCompanyId_PrevAndNext(Session session,
1558                    EmailAddress emailAddress, long companyId,
1559                    OrderByComparator<EmailAddress> orderByComparator, boolean previous) {
1560                    StringBundler query = null;
1561    
1562                    if (orderByComparator != null) {
1563                            query = new StringBundler(6 +
1564                                            (orderByComparator.getOrderByFields().length * 6));
1565                    }
1566                    else {
1567                            query = new StringBundler(3);
1568                    }
1569    
1570                    query.append(_SQL_SELECT_EMAILADDRESS_WHERE);
1571    
1572                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1573    
1574                    if (orderByComparator != null) {
1575                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1576    
1577                            if (orderByConditionFields.length > 0) {
1578                                    query.append(WHERE_AND);
1579                            }
1580    
1581                            for (int i = 0; i < orderByConditionFields.length; i++) {
1582                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1583                                    query.append(orderByConditionFields[i]);
1584    
1585                                    if ((i + 1) < orderByConditionFields.length) {
1586                                            if (orderByComparator.isAscending() ^ previous) {
1587                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1588                                            }
1589                                            else {
1590                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1591                                            }
1592                                    }
1593                                    else {
1594                                            if (orderByComparator.isAscending() ^ previous) {
1595                                                    query.append(WHERE_GREATER_THAN);
1596                                            }
1597                                            else {
1598                                                    query.append(WHERE_LESSER_THAN);
1599                                            }
1600                                    }
1601                            }
1602    
1603                            query.append(ORDER_BY_CLAUSE);
1604    
1605                            String[] orderByFields = orderByComparator.getOrderByFields();
1606    
1607                            for (int i = 0; i < orderByFields.length; i++) {
1608                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1609                                    query.append(orderByFields[i]);
1610    
1611                                    if ((i + 1) < orderByFields.length) {
1612                                            if (orderByComparator.isAscending() ^ previous) {
1613                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1614                                            }
1615                                            else {
1616                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1617                                            }
1618                                    }
1619                                    else {
1620                                            if (orderByComparator.isAscending() ^ previous) {
1621                                                    query.append(ORDER_BY_ASC);
1622                                            }
1623                                            else {
1624                                                    query.append(ORDER_BY_DESC);
1625                                            }
1626                                    }
1627                            }
1628                    }
1629                    else {
1630                            query.append(EmailAddressModelImpl.ORDER_BY_JPQL);
1631                    }
1632    
1633                    String sql = query.toString();
1634    
1635                    Query q = session.createQuery(sql);
1636    
1637                    q.setFirstResult(0);
1638                    q.setMaxResults(2);
1639    
1640                    QueryPos qPos = QueryPos.getInstance(q);
1641    
1642                    qPos.add(companyId);
1643    
1644                    if (orderByComparator != null) {
1645                            Object[] values = orderByComparator.getOrderByConditionValues(emailAddress);
1646    
1647                            for (Object value : values) {
1648                                    qPos.add(value);
1649                            }
1650                    }
1651    
1652                    List<EmailAddress> list = q.list();
1653    
1654                    if (list.size() == 2) {
1655                            return list.get(1);
1656                    }
1657                    else {
1658                            return null;
1659                    }
1660            }
1661    
1662            /**
1663             * Removes all the email addresses where companyId = &#63; from the database.
1664             *
1665             * @param companyId the company ID
1666             */
1667            @Override
1668            public void removeByCompanyId(long companyId) {
1669                    for (EmailAddress emailAddress : findByCompanyId(companyId,
1670                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1671                            remove(emailAddress);
1672                    }
1673            }
1674    
1675            /**
1676             * Returns the number of email addresses where companyId = &#63;.
1677             *
1678             * @param companyId the company ID
1679             * @return the number of matching email addresses
1680             */
1681            @Override
1682            public int countByCompanyId(long companyId) {
1683                    FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
1684    
1685                    Object[] finderArgs = new Object[] { companyId };
1686    
1687                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1688    
1689                    if (count == null) {
1690                            StringBundler query = new StringBundler(2);
1691    
1692                            query.append(_SQL_COUNT_EMAILADDRESS_WHERE);
1693    
1694                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1695    
1696                            String sql = query.toString();
1697    
1698                            Session session = null;
1699    
1700                            try {
1701                                    session = openSession();
1702    
1703                                    Query q = session.createQuery(sql);
1704    
1705                                    QueryPos qPos = QueryPos.getInstance(q);
1706    
1707                                    qPos.add(companyId);
1708    
1709                                    count = (Long)q.uniqueResult();
1710    
1711                                    finderCache.putResult(finderPath, finderArgs, count);
1712                            }
1713                            catch (Exception e) {
1714                                    finderCache.removeResult(finderPath, finderArgs);
1715    
1716                                    throw processException(e);
1717                            }
1718                            finally {
1719                                    closeSession(session);
1720                            }
1721                    }
1722    
1723                    return count.intValue();
1724            }
1725    
1726            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "emailAddress.companyId = ?";
1727            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(EmailAddressModelImpl.ENTITY_CACHE_ENABLED,
1728                            EmailAddressModelImpl.FINDER_CACHE_ENABLED, EmailAddressImpl.class,
1729                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUserId",
1730                            new String[] {
1731                                    Long.class.getName(),
1732                                    
1733                            Integer.class.getName(), Integer.class.getName(),
1734                                    OrderByComparator.class.getName()
1735                            });
1736            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID =
1737                    new FinderPath(EmailAddressModelImpl.ENTITY_CACHE_ENABLED,
1738                            EmailAddressModelImpl.FINDER_CACHE_ENABLED, EmailAddressImpl.class,
1739                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId",
1740                            new String[] { Long.class.getName() },
1741                            EmailAddressModelImpl.USERID_COLUMN_BITMASK |
1742                            EmailAddressModelImpl.CREATEDATE_COLUMN_BITMASK);
1743            public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(EmailAddressModelImpl.ENTITY_CACHE_ENABLED,
1744                            EmailAddressModelImpl.FINDER_CACHE_ENABLED, Long.class,
1745                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
1746                            new String[] { Long.class.getName() });
1747    
1748            /**
1749             * Returns all the email addresses where userId = &#63;.
1750             *
1751             * @param userId the user ID
1752             * @return the matching email addresses
1753             */
1754            @Override
1755            public List<EmailAddress> findByUserId(long userId) {
1756                    return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1757            }
1758    
1759            /**
1760             * Returns a range of all the email addresses where userId = &#63;.
1761             *
1762             * <p>
1763             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
1764             * </p>
1765             *
1766             * @param userId the user ID
1767             * @param start the lower bound of the range of email addresses
1768             * @param end the upper bound of the range of email addresses (not inclusive)
1769             * @return the range of matching email addresses
1770             */
1771            @Override
1772            public List<EmailAddress> findByUserId(long userId, int start, int end) {
1773                    return findByUserId(userId, start, end, null);
1774            }
1775    
1776            /**
1777             * Returns an ordered range of all the email addresses where userId = &#63;.
1778             *
1779             * <p>
1780             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
1781             * </p>
1782             *
1783             * @param userId the user ID
1784             * @param start the lower bound of the range of email addresses
1785             * @param end the upper bound of the range of email addresses (not inclusive)
1786             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1787             * @return the ordered range of matching email addresses
1788             */
1789            @Override
1790            public List<EmailAddress> findByUserId(long userId, int start, int end,
1791                    OrderByComparator<EmailAddress> orderByComparator) {
1792                    return findByUserId(userId, start, end, orderByComparator, true);
1793            }
1794    
1795            /**
1796             * Returns an ordered range of all the email addresses where userId = &#63;.
1797             *
1798             * <p>
1799             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
1800             * </p>
1801             *
1802             * @param userId the user ID
1803             * @param start the lower bound of the range of email addresses
1804             * @param end the upper bound of the range of email addresses (not inclusive)
1805             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1806             * @param retrieveFromCache whether to retrieve from the finder cache
1807             * @return the ordered range of matching email addresses
1808             */
1809            @Override
1810            public List<EmailAddress> findByUserId(long userId, int start, int end,
1811                    OrderByComparator<EmailAddress> orderByComparator,
1812                    boolean retrieveFromCache) {
1813                    boolean pagination = true;
1814                    FinderPath finderPath = null;
1815                    Object[] finderArgs = null;
1816    
1817                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1818                                    (orderByComparator == null)) {
1819                            pagination = false;
1820                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
1821                            finderArgs = new Object[] { userId };
1822                    }
1823                    else {
1824                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
1825                            finderArgs = new Object[] { userId, start, end, orderByComparator };
1826                    }
1827    
1828                    List<EmailAddress> list = null;
1829    
1830                    if (retrieveFromCache) {
1831                            list = (List<EmailAddress>)finderCache.getResult(finderPath,
1832                                            finderArgs, this);
1833    
1834                            if ((list != null) && !list.isEmpty()) {
1835                                    for (EmailAddress emailAddress : list) {
1836                                            if ((userId != emailAddress.getUserId())) {
1837                                                    list = null;
1838    
1839                                                    break;
1840                                            }
1841                                    }
1842                            }
1843                    }
1844    
1845                    if (list == null) {
1846                            StringBundler query = null;
1847    
1848                            if (orderByComparator != null) {
1849                                    query = new StringBundler(3 +
1850                                                    (orderByComparator.getOrderByFields().length * 3));
1851                            }
1852                            else {
1853                                    query = new StringBundler(3);
1854                            }
1855    
1856                            query.append(_SQL_SELECT_EMAILADDRESS_WHERE);
1857    
1858                            query.append(_FINDER_COLUMN_USERID_USERID_2);
1859    
1860                            if (orderByComparator != null) {
1861                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1862                                            orderByComparator);
1863                            }
1864                            else
1865                             if (pagination) {
1866                                    query.append(EmailAddressModelImpl.ORDER_BY_JPQL);
1867                            }
1868    
1869                            String sql = query.toString();
1870    
1871                            Session session = null;
1872    
1873                            try {
1874                                    session = openSession();
1875    
1876                                    Query q = session.createQuery(sql);
1877    
1878                                    QueryPos qPos = QueryPos.getInstance(q);
1879    
1880                                    qPos.add(userId);
1881    
1882                                    if (!pagination) {
1883                                            list = (List<EmailAddress>)QueryUtil.list(q, getDialect(),
1884                                                            start, end, false);
1885    
1886                                            Collections.sort(list);
1887    
1888                                            list = Collections.unmodifiableList(list);
1889                                    }
1890                                    else {
1891                                            list = (List<EmailAddress>)QueryUtil.list(q, getDialect(),
1892                                                            start, end);
1893                                    }
1894    
1895                                    cacheResult(list);
1896    
1897                                    finderCache.putResult(finderPath, finderArgs, list);
1898                            }
1899                            catch (Exception e) {
1900                                    finderCache.removeResult(finderPath, finderArgs);
1901    
1902                                    throw processException(e);
1903                            }
1904                            finally {
1905                                    closeSession(session);
1906                            }
1907                    }
1908    
1909                    return list;
1910            }
1911    
1912            /**
1913             * Returns the first email address in the ordered set where userId = &#63;.
1914             *
1915             * @param userId the user ID
1916             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1917             * @return the first matching email address
1918             * @throws NoSuchEmailAddressException if a matching email address could not be found
1919             */
1920            @Override
1921            public EmailAddress findByUserId_First(long userId,
1922                    OrderByComparator<EmailAddress> orderByComparator)
1923                    throws NoSuchEmailAddressException {
1924                    EmailAddress emailAddress = fetchByUserId_First(userId,
1925                                    orderByComparator);
1926    
1927                    if (emailAddress != null) {
1928                            return emailAddress;
1929                    }
1930    
1931                    StringBundler msg = new StringBundler(4);
1932    
1933                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1934    
1935                    msg.append("userId=");
1936                    msg.append(userId);
1937    
1938                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1939    
1940                    throw new NoSuchEmailAddressException(msg.toString());
1941            }
1942    
1943            /**
1944             * Returns the first email address in the ordered set where userId = &#63;.
1945             *
1946             * @param userId the user ID
1947             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1948             * @return the first matching email address, or <code>null</code> if a matching email address could not be found
1949             */
1950            @Override
1951            public EmailAddress fetchByUserId_First(long userId,
1952                    OrderByComparator<EmailAddress> orderByComparator) {
1953                    List<EmailAddress> list = findByUserId(userId, 0, 1, orderByComparator);
1954    
1955                    if (!list.isEmpty()) {
1956                            return list.get(0);
1957                    }
1958    
1959                    return null;
1960            }
1961    
1962            /**
1963             * Returns the last email address in the ordered set where userId = &#63;.
1964             *
1965             * @param userId the user ID
1966             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1967             * @return the last matching email address
1968             * @throws NoSuchEmailAddressException if a matching email address could not be found
1969             */
1970            @Override
1971            public EmailAddress findByUserId_Last(long userId,
1972                    OrderByComparator<EmailAddress> orderByComparator)
1973                    throws NoSuchEmailAddressException {
1974                    EmailAddress emailAddress = fetchByUserId_Last(userId, orderByComparator);
1975    
1976                    if (emailAddress != null) {
1977                            return emailAddress;
1978                    }
1979    
1980                    StringBundler msg = new StringBundler(4);
1981    
1982                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1983    
1984                    msg.append("userId=");
1985                    msg.append(userId);
1986    
1987                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1988    
1989                    throw new NoSuchEmailAddressException(msg.toString());
1990            }
1991    
1992            /**
1993             * Returns the last email address in the ordered set where userId = &#63;.
1994             *
1995             * @param userId the user ID
1996             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1997             * @return the last matching email address, or <code>null</code> if a matching email address could not be found
1998             */
1999            @Override
2000            public EmailAddress fetchByUserId_Last(long userId,
2001                    OrderByComparator<EmailAddress> orderByComparator) {
2002                    int count = countByUserId(userId);
2003    
2004                    if (count == 0) {
2005                            return null;
2006                    }
2007    
2008                    List<EmailAddress> list = findByUserId(userId, count - 1, count,
2009                                    orderByComparator);
2010    
2011                    if (!list.isEmpty()) {
2012                            return list.get(0);
2013                    }
2014    
2015                    return null;
2016            }
2017    
2018            /**
2019             * Returns the email addresses before and after the current email address in the ordered set where userId = &#63;.
2020             *
2021             * @param emailAddressId the primary key of the current email address
2022             * @param userId the user ID
2023             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2024             * @return the previous, current, and next email address
2025             * @throws NoSuchEmailAddressException if a email address with the primary key could not be found
2026             */
2027            @Override
2028            public EmailAddress[] findByUserId_PrevAndNext(long emailAddressId,
2029                    long userId, OrderByComparator<EmailAddress> orderByComparator)
2030                    throws NoSuchEmailAddressException {
2031                    EmailAddress emailAddress = findByPrimaryKey(emailAddressId);
2032    
2033                    Session session = null;
2034    
2035                    try {
2036                            session = openSession();
2037    
2038                            EmailAddress[] array = new EmailAddressImpl[3];
2039    
2040                            array[0] = getByUserId_PrevAndNext(session, emailAddress, userId,
2041                                            orderByComparator, true);
2042    
2043                            array[1] = emailAddress;
2044    
2045                            array[2] = getByUserId_PrevAndNext(session, emailAddress, userId,
2046                                            orderByComparator, false);
2047    
2048                            return array;
2049                    }
2050                    catch (Exception e) {
2051                            throw processException(e);
2052                    }
2053                    finally {
2054                            closeSession(session);
2055                    }
2056            }
2057    
2058            protected EmailAddress getByUserId_PrevAndNext(Session session,
2059                    EmailAddress emailAddress, long userId,
2060                    OrderByComparator<EmailAddress> orderByComparator, boolean previous) {
2061                    StringBundler query = null;
2062    
2063                    if (orderByComparator != null) {
2064                            query = new StringBundler(6 +
2065                                            (orderByComparator.getOrderByFields().length * 6));
2066                    }
2067                    else {
2068                            query = new StringBundler(3);
2069                    }
2070    
2071                    query.append(_SQL_SELECT_EMAILADDRESS_WHERE);
2072    
2073                    query.append(_FINDER_COLUMN_USERID_USERID_2);
2074    
2075                    if (orderByComparator != null) {
2076                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2077    
2078                            if (orderByConditionFields.length > 0) {
2079                                    query.append(WHERE_AND);
2080                            }
2081    
2082                            for (int i = 0; i < orderByConditionFields.length; i++) {
2083                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2084                                    query.append(orderByConditionFields[i]);
2085    
2086                                    if ((i + 1) < orderByConditionFields.length) {
2087                                            if (orderByComparator.isAscending() ^ previous) {
2088                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2089                                            }
2090                                            else {
2091                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2092                                            }
2093                                    }
2094                                    else {
2095                                            if (orderByComparator.isAscending() ^ previous) {
2096                                                    query.append(WHERE_GREATER_THAN);
2097                                            }
2098                                            else {
2099                                                    query.append(WHERE_LESSER_THAN);
2100                                            }
2101                                    }
2102                            }
2103    
2104                            query.append(ORDER_BY_CLAUSE);
2105    
2106                            String[] orderByFields = orderByComparator.getOrderByFields();
2107    
2108                            for (int i = 0; i < orderByFields.length; i++) {
2109                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2110                                    query.append(orderByFields[i]);
2111    
2112                                    if ((i + 1) < orderByFields.length) {
2113                                            if (orderByComparator.isAscending() ^ previous) {
2114                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2115                                            }
2116                                            else {
2117                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2118                                            }
2119                                    }
2120                                    else {
2121                                            if (orderByComparator.isAscending() ^ previous) {
2122                                                    query.append(ORDER_BY_ASC);
2123                                            }
2124                                            else {
2125                                                    query.append(ORDER_BY_DESC);
2126                                            }
2127                                    }
2128                            }
2129                    }
2130                    else {
2131                            query.append(EmailAddressModelImpl.ORDER_BY_JPQL);
2132                    }
2133    
2134                    String sql = query.toString();
2135    
2136                    Query q = session.createQuery(sql);
2137    
2138                    q.setFirstResult(0);
2139                    q.setMaxResults(2);
2140    
2141                    QueryPos qPos = QueryPos.getInstance(q);
2142    
2143                    qPos.add(userId);
2144    
2145                    if (orderByComparator != null) {
2146                            Object[] values = orderByComparator.getOrderByConditionValues(emailAddress);
2147    
2148                            for (Object value : values) {
2149                                    qPos.add(value);
2150                            }
2151                    }
2152    
2153                    List<EmailAddress> list = q.list();
2154    
2155                    if (list.size() == 2) {
2156                            return list.get(1);
2157                    }
2158                    else {
2159                            return null;
2160                    }
2161            }
2162    
2163            /**
2164             * Removes all the email addresses where userId = &#63; from the database.
2165             *
2166             * @param userId the user ID
2167             */
2168            @Override
2169            public void removeByUserId(long userId) {
2170                    for (EmailAddress emailAddress : findByUserId(userId,
2171                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2172                            remove(emailAddress);
2173                    }
2174            }
2175    
2176            /**
2177             * Returns the number of email addresses where userId = &#63;.
2178             *
2179             * @param userId the user ID
2180             * @return the number of matching email addresses
2181             */
2182            @Override
2183            public int countByUserId(long userId) {
2184                    FinderPath finderPath = FINDER_PATH_COUNT_BY_USERID;
2185    
2186                    Object[] finderArgs = new Object[] { userId };
2187    
2188                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
2189    
2190                    if (count == null) {
2191                            StringBundler query = new StringBundler(2);
2192    
2193                            query.append(_SQL_COUNT_EMAILADDRESS_WHERE);
2194    
2195                            query.append(_FINDER_COLUMN_USERID_USERID_2);
2196    
2197                            String sql = query.toString();
2198    
2199                            Session session = null;
2200    
2201                            try {
2202                                    session = openSession();
2203    
2204                                    Query q = session.createQuery(sql);
2205    
2206                                    QueryPos qPos = QueryPos.getInstance(q);
2207    
2208                                    qPos.add(userId);
2209    
2210                                    count = (Long)q.uniqueResult();
2211    
2212                                    finderCache.putResult(finderPath, finderArgs, count);
2213                            }
2214                            catch (Exception e) {
2215                                    finderCache.removeResult(finderPath, finderArgs);
2216    
2217                                    throw processException(e);
2218                            }
2219                            finally {
2220                                    closeSession(session);
2221                            }
2222                    }
2223    
2224                    return count.intValue();
2225            }
2226    
2227            private static final String _FINDER_COLUMN_USERID_USERID_2 = "emailAddress.userId = ?";
2228            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C = new FinderPath(EmailAddressModelImpl.ENTITY_CACHE_ENABLED,
2229                            EmailAddressModelImpl.FINDER_CACHE_ENABLED, EmailAddressImpl.class,
2230                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C",
2231                            new String[] {
2232                                    Long.class.getName(), Long.class.getName(),
2233                                    
2234                            Integer.class.getName(), Integer.class.getName(),
2235                                    OrderByComparator.class.getName()
2236                            });
2237            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C = new FinderPath(EmailAddressModelImpl.ENTITY_CACHE_ENABLED,
2238                            EmailAddressModelImpl.FINDER_CACHE_ENABLED, EmailAddressImpl.class,
2239                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C",
2240                            new String[] { Long.class.getName(), Long.class.getName() },
2241                            EmailAddressModelImpl.COMPANYID_COLUMN_BITMASK |
2242                            EmailAddressModelImpl.CLASSNAMEID_COLUMN_BITMASK |
2243                            EmailAddressModelImpl.CREATEDATE_COLUMN_BITMASK);
2244            public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(EmailAddressModelImpl.ENTITY_CACHE_ENABLED,
2245                            EmailAddressModelImpl.FINDER_CACHE_ENABLED, Long.class,
2246                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C",
2247                            new String[] { Long.class.getName(), Long.class.getName() });
2248    
2249            /**
2250             * Returns all the email addresses where companyId = &#63; and classNameId = &#63;.
2251             *
2252             * @param companyId the company ID
2253             * @param classNameId the class name ID
2254             * @return the matching email addresses
2255             */
2256            @Override
2257            public List<EmailAddress> findByC_C(long companyId, long classNameId) {
2258                    return findByC_C(companyId, classNameId, QueryUtil.ALL_POS,
2259                            QueryUtil.ALL_POS, null);
2260            }
2261    
2262            /**
2263             * Returns a range of all the email addresses where companyId = &#63; and classNameId = &#63;.
2264             *
2265             * <p>
2266             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
2267             * </p>
2268             *
2269             * @param companyId the company ID
2270             * @param classNameId the class name ID
2271             * @param start the lower bound of the range of email addresses
2272             * @param end the upper bound of the range of email addresses (not inclusive)
2273             * @return the range of matching email addresses
2274             */
2275            @Override
2276            public List<EmailAddress> findByC_C(long companyId, long classNameId,
2277                    int start, int end) {
2278                    return findByC_C(companyId, classNameId, start, end, null);
2279            }
2280    
2281            /**
2282             * Returns an ordered range of all the email addresses where companyId = &#63; and classNameId = &#63;.
2283             *
2284             * <p>
2285             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
2286             * </p>
2287             *
2288             * @param companyId the company ID
2289             * @param classNameId the class name ID
2290             * @param start the lower bound of the range of email addresses
2291             * @param end the upper bound of the range of email addresses (not inclusive)
2292             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2293             * @return the ordered range of matching email addresses
2294             */
2295            @Override
2296            public List<EmailAddress> findByC_C(long companyId, long classNameId,
2297                    int start, int end, OrderByComparator<EmailAddress> orderByComparator) {
2298                    return findByC_C(companyId, classNameId, start, end, orderByComparator,
2299                            true);
2300            }
2301    
2302            /**
2303             * Returns an ordered range of all the email addresses where companyId = &#63; and classNameId = &#63;.
2304             *
2305             * <p>
2306             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
2307             * </p>
2308             *
2309             * @param companyId the company ID
2310             * @param classNameId the class name ID
2311             * @param start the lower bound of the range of email addresses
2312             * @param end the upper bound of the range of email addresses (not inclusive)
2313             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2314             * @param retrieveFromCache whether to retrieve from the finder cache
2315             * @return the ordered range of matching email addresses
2316             */
2317            @Override
2318            public List<EmailAddress> findByC_C(long companyId, long classNameId,
2319                    int start, int end, OrderByComparator<EmailAddress> orderByComparator,
2320                    boolean retrieveFromCache) {
2321                    boolean pagination = true;
2322                    FinderPath finderPath = null;
2323                    Object[] finderArgs = null;
2324    
2325                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2326                                    (orderByComparator == null)) {
2327                            pagination = false;
2328                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C;
2329                            finderArgs = new Object[] { companyId, classNameId };
2330                    }
2331                    else {
2332                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C;
2333                            finderArgs = new Object[] {
2334                                            companyId, classNameId,
2335                                            
2336                                            start, end, orderByComparator
2337                                    };
2338                    }
2339    
2340                    List<EmailAddress> list = null;
2341    
2342                    if (retrieveFromCache) {
2343                            list = (List<EmailAddress>)finderCache.getResult(finderPath,
2344                                            finderArgs, this);
2345    
2346                            if ((list != null) && !list.isEmpty()) {
2347                                    for (EmailAddress emailAddress : list) {
2348                                            if ((companyId != emailAddress.getCompanyId()) ||
2349                                                            (classNameId != emailAddress.getClassNameId())) {
2350                                                    list = null;
2351    
2352                                                    break;
2353                                            }
2354                                    }
2355                            }
2356                    }
2357    
2358                    if (list == null) {
2359                            StringBundler query = null;
2360    
2361                            if (orderByComparator != null) {
2362                                    query = new StringBundler(4 +
2363                                                    (orderByComparator.getOrderByFields().length * 3));
2364                            }
2365                            else {
2366                                    query = new StringBundler(4);
2367                            }
2368    
2369                            query.append(_SQL_SELECT_EMAILADDRESS_WHERE);
2370    
2371                            query.append(_FINDER_COLUMN_C_C_COMPANYID_2);
2372    
2373                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
2374    
2375                            if (orderByComparator != null) {
2376                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2377                                            orderByComparator);
2378                            }
2379                            else
2380                             if (pagination) {
2381                                    query.append(EmailAddressModelImpl.ORDER_BY_JPQL);
2382                            }
2383    
2384                            String sql = query.toString();
2385    
2386                            Session session = null;
2387    
2388                            try {
2389                                    session = openSession();
2390    
2391                                    Query q = session.createQuery(sql);
2392    
2393                                    QueryPos qPos = QueryPos.getInstance(q);
2394    
2395                                    qPos.add(companyId);
2396    
2397                                    qPos.add(classNameId);
2398    
2399                                    if (!pagination) {
2400                                            list = (List<EmailAddress>)QueryUtil.list(q, getDialect(),
2401                                                            start, end, false);
2402    
2403                                            Collections.sort(list);
2404    
2405                                            list = Collections.unmodifiableList(list);
2406                                    }
2407                                    else {
2408                                            list = (List<EmailAddress>)QueryUtil.list(q, getDialect(),
2409                                                            start, end);
2410                                    }
2411    
2412                                    cacheResult(list);
2413    
2414                                    finderCache.putResult(finderPath, finderArgs, list);
2415                            }
2416                            catch (Exception e) {
2417                                    finderCache.removeResult(finderPath, finderArgs);
2418    
2419                                    throw processException(e);
2420                            }
2421                            finally {
2422                                    closeSession(session);
2423                            }
2424                    }
2425    
2426                    return list;
2427            }
2428    
2429            /**
2430             * Returns the first email address in the ordered set where companyId = &#63; and classNameId = &#63;.
2431             *
2432             * @param companyId the company ID
2433             * @param classNameId the class name ID
2434             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2435             * @return the first matching email address
2436             * @throws NoSuchEmailAddressException if a matching email address could not be found
2437             */
2438            @Override
2439            public EmailAddress findByC_C_First(long companyId, long classNameId,
2440                    OrderByComparator<EmailAddress> orderByComparator)
2441                    throws NoSuchEmailAddressException {
2442                    EmailAddress emailAddress = fetchByC_C_First(companyId, classNameId,
2443                                    orderByComparator);
2444    
2445                    if (emailAddress != null) {
2446                            return emailAddress;
2447                    }
2448    
2449                    StringBundler msg = new StringBundler(6);
2450    
2451                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2452    
2453                    msg.append("companyId=");
2454                    msg.append(companyId);
2455    
2456                    msg.append(", classNameId=");
2457                    msg.append(classNameId);
2458    
2459                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2460    
2461                    throw new NoSuchEmailAddressException(msg.toString());
2462            }
2463    
2464            /**
2465             * Returns the first email address in the ordered set where companyId = &#63; and classNameId = &#63;.
2466             *
2467             * @param companyId the company ID
2468             * @param classNameId the class name ID
2469             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2470             * @return the first matching email address, or <code>null</code> if a matching email address could not be found
2471             */
2472            @Override
2473            public EmailAddress fetchByC_C_First(long companyId, long classNameId,
2474                    OrderByComparator<EmailAddress> orderByComparator) {
2475                    List<EmailAddress> list = findByC_C(companyId, classNameId, 0, 1,
2476                                    orderByComparator);
2477    
2478                    if (!list.isEmpty()) {
2479                            return list.get(0);
2480                    }
2481    
2482                    return null;
2483            }
2484    
2485            /**
2486             * Returns the last email address in the ordered set where companyId = &#63; and classNameId = &#63;.
2487             *
2488             * @param companyId the company ID
2489             * @param classNameId the class name ID
2490             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2491             * @return the last matching email address
2492             * @throws NoSuchEmailAddressException if a matching email address could not be found
2493             */
2494            @Override
2495            public EmailAddress findByC_C_Last(long companyId, long classNameId,
2496                    OrderByComparator<EmailAddress> orderByComparator)
2497                    throws NoSuchEmailAddressException {
2498                    EmailAddress emailAddress = fetchByC_C_Last(companyId, classNameId,
2499                                    orderByComparator);
2500    
2501                    if (emailAddress != null) {
2502                            return emailAddress;
2503                    }
2504    
2505                    StringBundler msg = new StringBundler(6);
2506    
2507                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2508    
2509                    msg.append("companyId=");
2510                    msg.append(companyId);
2511    
2512                    msg.append(", classNameId=");
2513                    msg.append(classNameId);
2514    
2515                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2516    
2517                    throw new NoSuchEmailAddressException(msg.toString());
2518            }
2519    
2520            /**
2521             * Returns the last email address in the ordered set where companyId = &#63; and classNameId = &#63;.
2522             *
2523             * @param companyId the company ID
2524             * @param classNameId the class name ID
2525             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2526             * @return the last matching email address, or <code>null</code> if a matching email address could not be found
2527             */
2528            @Override
2529            public EmailAddress fetchByC_C_Last(long companyId, long classNameId,
2530                    OrderByComparator<EmailAddress> orderByComparator) {
2531                    int count = countByC_C(companyId, classNameId);
2532    
2533                    if (count == 0) {
2534                            return null;
2535                    }
2536    
2537                    List<EmailAddress> list = findByC_C(companyId, classNameId, count - 1,
2538                                    count, orderByComparator);
2539    
2540                    if (!list.isEmpty()) {
2541                            return list.get(0);
2542                    }
2543    
2544                    return null;
2545            }
2546    
2547            /**
2548             * Returns the email addresses before and after the current email address in the ordered set where companyId = &#63; and classNameId = &#63;.
2549             *
2550             * @param emailAddressId the primary key of the current email address
2551             * @param companyId the company ID
2552             * @param classNameId the class name ID
2553             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2554             * @return the previous, current, and next email address
2555             * @throws NoSuchEmailAddressException if a email address with the primary key could not be found
2556             */
2557            @Override
2558            public EmailAddress[] findByC_C_PrevAndNext(long emailAddressId,
2559                    long companyId, long classNameId,
2560                    OrderByComparator<EmailAddress> orderByComparator)
2561                    throws NoSuchEmailAddressException {
2562                    EmailAddress emailAddress = findByPrimaryKey(emailAddressId);
2563    
2564                    Session session = null;
2565    
2566                    try {
2567                            session = openSession();
2568    
2569                            EmailAddress[] array = new EmailAddressImpl[3];
2570    
2571                            array[0] = getByC_C_PrevAndNext(session, emailAddress, companyId,
2572                                            classNameId, orderByComparator, true);
2573    
2574                            array[1] = emailAddress;
2575    
2576                            array[2] = getByC_C_PrevAndNext(session, emailAddress, companyId,
2577                                            classNameId, orderByComparator, false);
2578    
2579                            return array;
2580                    }
2581                    catch (Exception e) {
2582                            throw processException(e);
2583                    }
2584                    finally {
2585                            closeSession(session);
2586                    }
2587            }
2588    
2589            protected EmailAddress getByC_C_PrevAndNext(Session session,
2590                    EmailAddress emailAddress, long companyId, long classNameId,
2591                    OrderByComparator<EmailAddress> orderByComparator, boolean previous) {
2592                    StringBundler query = null;
2593    
2594                    if (orderByComparator != null) {
2595                            query = new StringBundler(6 +
2596                                            (orderByComparator.getOrderByFields().length * 6));
2597                    }
2598                    else {
2599                            query = new StringBundler(3);
2600                    }
2601    
2602                    query.append(_SQL_SELECT_EMAILADDRESS_WHERE);
2603    
2604                    query.append(_FINDER_COLUMN_C_C_COMPANYID_2);
2605    
2606                    query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
2607    
2608                    if (orderByComparator != null) {
2609                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2610    
2611                            if (orderByConditionFields.length > 0) {
2612                                    query.append(WHERE_AND);
2613                            }
2614    
2615                            for (int i = 0; i < orderByConditionFields.length; i++) {
2616                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2617                                    query.append(orderByConditionFields[i]);
2618    
2619                                    if ((i + 1) < orderByConditionFields.length) {
2620                                            if (orderByComparator.isAscending() ^ previous) {
2621                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2622                                            }
2623                                            else {
2624                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2625                                            }
2626                                    }
2627                                    else {
2628                                            if (orderByComparator.isAscending() ^ previous) {
2629                                                    query.append(WHERE_GREATER_THAN);
2630                                            }
2631                                            else {
2632                                                    query.append(WHERE_LESSER_THAN);
2633                                            }
2634                                    }
2635                            }
2636    
2637                            query.append(ORDER_BY_CLAUSE);
2638    
2639                            String[] orderByFields = orderByComparator.getOrderByFields();
2640    
2641                            for (int i = 0; i < orderByFields.length; i++) {
2642                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2643                                    query.append(orderByFields[i]);
2644    
2645                                    if ((i + 1) < orderByFields.length) {
2646                                            if (orderByComparator.isAscending() ^ previous) {
2647                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2648                                            }
2649                                            else {
2650                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2651                                            }
2652                                    }
2653                                    else {
2654                                            if (orderByComparator.isAscending() ^ previous) {
2655                                                    query.append(ORDER_BY_ASC);
2656                                            }
2657                                            else {
2658                                                    query.append(ORDER_BY_DESC);
2659                                            }
2660                                    }
2661                            }
2662                    }
2663                    else {
2664                            query.append(EmailAddressModelImpl.ORDER_BY_JPQL);
2665                    }
2666    
2667                    String sql = query.toString();
2668    
2669                    Query q = session.createQuery(sql);
2670    
2671                    q.setFirstResult(0);
2672                    q.setMaxResults(2);
2673    
2674                    QueryPos qPos = QueryPos.getInstance(q);
2675    
2676                    qPos.add(companyId);
2677    
2678                    qPos.add(classNameId);
2679    
2680                    if (orderByComparator != null) {
2681                            Object[] values = orderByComparator.getOrderByConditionValues(emailAddress);
2682    
2683                            for (Object value : values) {
2684                                    qPos.add(value);
2685                            }
2686                    }
2687    
2688                    List<EmailAddress> list = q.list();
2689    
2690                    if (list.size() == 2) {
2691                            return list.get(1);
2692                    }
2693                    else {
2694                            return null;
2695                    }
2696            }
2697    
2698            /**
2699             * Removes all the email addresses where companyId = &#63; and classNameId = &#63; from the database.
2700             *
2701             * @param companyId the company ID
2702             * @param classNameId the class name ID
2703             */
2704            @Override
2705            public void removeByC_C(long companyId, long classNameId) {
2706                    for (EmailAddress emailAddress : findByC_C(companyId, classNameId,
2707                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2708                            remove(emailAddress);
2709                    }
2710            }
2711    
2712            /**
2713             * Returns the number of email addresses where companyId = &#63; and classNameId = &#63;.
2714             *
2715             * @param companyId the company ID
2716             * @param classNameId the class name ID
2717             * @return the number of matching email addresses
2718             */
2719            @Override
2720            public int countByC_C(long companyId, long classNameId) {
2721                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C;
2722    
2723                    Object[] finderArgs = new Object[] { companyId, classNameId };
2724    
2725                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
2726    
2727                    if (count == null) {
2728                            StringBundler query = new StringBundler(3);
2729    
2730                            query.append(_SQL_COUNT_EMAILADDRESS_WHERE);
2731    
2732                            query.append(_FINDER_COLUMN_C_C_COMPANYID_2);
2733    
2734                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
2735    
2736                            String sql = query.toString();
2737    
2738                            Session session = null;
2739    
2740                            try {
2741                                    session = openSession();
2742    
2743                                    Query q = session.createQuery(sql);
2744    
2745                                    QueryPos qPos = QueryPos.getInstance(q);
2746    
2747                                    qPos.add(companyId);
2748    
2749                                    qPos.add(classNameId);
2750    
2751                                    count = (Long)q.uniqueResult();
2752    
2753                                    finderCache.putResult(finderPath, finderArgs, count);
2754                            }
2755                            catch (Exception e) {
2756                                    finderCache.removeResult(finderPath, finderArgs);
2757    
2758                                    throw processException(e);
2759                            }
2760                            finally {
2761                                    closeSession(session);
2762                            }
2763                    }
2764    
2765                    return count.intValue();
2766            }
2767    
2768            private static final String _FINDER_COLUMN_C_C_COMPANYID_2 = "emailAddress.companyId = ? AND ";
2769            private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "emailAddress.classNameId = ?";
2770            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_C = new FinderPath(EmailAddressModelImpl.ENTITY_CACHE_ENABLED,
2771                            EmailAddressModelImpl.FINDER_CACHE_ENABLED, EmailAddressImpl.class,
2772                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C_C",
2773                            new String[] {
2774                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
2775                                    
2776                            Integer.class.getName(), Integer.class.getName(),
2777                                    OrderByComparator.class.getName()
2778                            });
2779            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C = new FinderPath(EmailAddressModelImpl.ENTITY_CACHE_ENABLED,
2780                            EmailAddressModelImpl.FINDER_CACHE_ENABLED, EmailAddressImpl.class,
2781                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C_C",
2782                            new String[] {
2783                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
2784                            },
2785                            EmailAddressModelImpl.COMPANYID_COLUMN_BITMASK |
2786                            EmailAddressModelImpl.CLASSNAMEID_COLUMN_BITMASK |
2787                            EmailAddressModelImpl.CLASSPK_COLUMN_BITMASK |
2788                            EmailAddressModelImpl.CREATEDATE_COLUMN_BITMASK);
2789            public static final FinderPath FINDER_PATH_COUNT_BY_C_C_C = new FinderPath(EmailAddressModelImpl.ENTITY_CACHE_ENABLED,
2790                            EmailAddressModelImpl.FINDER_CACHE_ENABLED, Long.class,
2791                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_C",
2792                            new String[] {
2793                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
2794                            });
2795    
2796            /**
2797             * Returns all the email addresses where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
2798             *
2799             * @param companyId the company ID
2800             * @param classNameId the class name ID
2801             * @param classPK the class p k
2802             * @return the matching email addresses
2803             */
2804            @Override
2805            public List<EmailAddress> findByC_C_C(long companyId, long classNameId,
2806                    long classPK) {
2807                    return findByC_C_C(companyId, classNameId, classPK, QueryUtil.ALL_POS,
2808                            QueryUtil.ALL_POS, null);
2809            }
2810    
2811            /**
2812             * Returns a range of all the email addresses where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
2813             *
2814             * <p>
2815             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
2816             * </p>
2817             *
2818             * @param companyId the company ID
2819             * @param classNameId the class name ID
2820             * @param classPK the class p k
2821             * @param start the lower bound of the range of email addresses
2822             * @param end the upper bound of the range of email addresses (not inclusive)
2823             * @return the range of matching email addresses
2824             */
2825            @Override
2826            public List<EmailAddress> findByC_C_C(long companyId, long classNameId,
2827                    long classPK, int start, int end) {
2828                    return findByC_C_C(companyId, classNameId, classPK, start, end, null);
2829            }
2830    
2831            /**
2832             * Returns an ordered range of all the email addresses where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
2833             *
2834             * <p>
2835             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
2836             * </p>
2837             *
2838             * @param companyId the company ID
2839             * @param classNameId the class name ID
2840             * @param classPK the class p k
2841             * @param start the lower bound of the range of email addresses
2842             * @param end the upper bound of the range of email addresses (not inclusive)
2843             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2844             * @return the ordered range of matching email addresses
2845             */
2846            @Override
2847            public List<EmailAddress> findByC_C_C(long companyId, long classNameId,
2848                    long classPK, int start, int end,
2849                    OrderByComparator<EmailAddress> orderByComparator) {
2850                    return findByC_C_C(companyId, classNameId, classPK, start, end,
2851                            orderByComparator, true);
2852            }
2853    
2854            /**
2855             * Returns an ordered range of all the email addresses where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
2856             *
2857             * <p>
2858             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
2859             * </p>
2860             *
2861             * @param companyId the company ID
2862             * @param classNameId the class name ID
2863             * @param classPK the class p k
2864             * @param start the lower bound of the range of email addresses
2865             * @param end the upper bound of the range of email addresses (not inclusive)
2866             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2867             * @param retrieveFromCache whether to retrieve from the finder cache
2868             * @return the ordered range of matching email addresses
2869             */
2870            @Override
2871            public List<EmailAddress> findByC_C_C(long companyId, long classNameId,
2872                    long classPK, int start, int end,
2873                    OrderByComparator<EmailAddress> orderByComparator,
2874                    boolean retrieveFromCache) {
2875                    boolean pagination = true;
2876                    FinderPath finderPath = null;
2877                    Object[] finderArgs = null;
2878    
2879                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2880                                    (orderByComparator == null)) {
2881                            pagination = false;
2882                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C;
2883                            finderArgs = new Object[] { companyId, classNameId, classPK };
2884                    }
2885                    else {
2886                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_C;
2887                            finderArgs = new Object[] {
2888                                            companyId, classNameId, classPK,
2889                                            
2890                                            start, end, orderByComparator
2891                                    };
2892                    }
2893    
2894                    List<EmailAddress> list = null;
2895    
2896                    if (retrieveFromCache) {
2897                            list = (List<EmailAddress>)finderCache.getResult(finderPath,
2898                                            finderArgs, this);
2899    
2900                            if ((list != null) && !list.isEmpty()) {
2901                                    for (EmailAddress emailAddress : list) {
2902                                            if ((companyId != emailAddress.getCompanyId()) ||
2903                                                            (classNameId != emailAddress.getClassNameId()) ||
2904                                                            (classPK != emailAddress.getClassPK())) {
2905                                                    list = null;
2906    
2907                                                    break;
2908                                            }
2909                                    }
2910                            }
2911                    }
2912    
2913                    if (list == null) {
2914                            StringBundler query = null;
2915    
2916                            if (orderByComparator != null) {
2917                                    query = new StringBundler(5 +
2918                                                    (orderByComparator.getOrderByFields().length * 3));
2919                            }
2920                            else {
2921                                    query = new StringBundler(5);
2922                            }
2923    
2924                            query.append(_SQL_SELECT_EMAILADDRESS_WHERE);
2925    
2926                            query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
2927    
2928                            query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
2929    
2930                            query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
2931    
2932                            if (orderByComparator != null) {
2933                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2934                                            orderByComparator);
2935                            }
2936                            else
2937                             if (pagination) {
2938                                    query.append(EmailAddressModelImpl.ORDER_BY_JPQL);
2939                            }
2940    
2941                            String sql = query.toString();
2942    
2943                            Session session = null;
2944    
2945                            try {
2946                                    session = openSession();
2947    
2948                                    Query q = session.createQuery(sql);
2949    
2950                                    QueryPos qPos = QueryPos.getInstance(q);
2951    
2952                                    qPos.add(companyId);
2953    
2954                                    qPos.add(classNameId);
2955    
2956                                    qPos.add(classPK);
2957    
2958                                    if (!pagination) {
2959                                            list = (List<EmailAddress>)QueryUtil.list(q, getDialect(),
2960                                                            start, end, false);
2961    
2962                                            Collections.sort(list);
2963    
2964                                            list = Collections.unmodifiableList(list);
2965                                    }
2966                                    else {
2967                                            list = (List<EmailAddress>)QueryUtil.list(q, getDialect(),
2968                                                            start, end);
2969                                    }
2970    
2971                                    cacheResult(list);
2972    
2973                                    finderCache.putResult(finderPath, finderArgs, list);
2974                            }
2975                            catch (Exception e) {
2976                                    finderCache.removeResult(finderPath, finderArgs);
2977    
2978                                    throw processException(e);
2979                            }
2980                            finally {
2981                                    closeSession(session);
2982                            }
2983                    }
2984    
2985                    return list;
2986            }
2987    
2988            /**
2989             * Returns the first email address in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
2990             *
2991             * @param companyId the company ID
2992             * @param classNameId the class name ID
2993             * @param classPK the class p k
2994             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2995             * @return the first matching email address
2996             * @throws NoSuchEmailAddressException if a matching email address could not be found
2997             */
2998            @Override
2999            public EmailAddress findByC_C_C_First(long companyId, long classNameId,
3000                    long classPK, OrderByComparator<EmailAddress> orderByComparator)
3001                    throws NoSuchEmailAddressException {
3002                    EmailAddress emailAddress = fetchByC_C_C_First(companyId, classNameId,
3003                                    classPK, orderByComparator);
3004    
3005                    if (emailAddress != null) {
3006                            return emailAddress;
3007                    }
3008    
3009                    StringBundler msg = new StringBundler(8);
3010    
3011                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3012    
3013                    msg.append("companyId=");
3014                    msg.append(companyId);
3015    
3016                    msg.append(", classNameId=");
3017                    msg.append(classNameId);
3018    
3019                    msg.append(", classPK=");
3020                    msg.append(classPK);
3021    
3022                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3023    
3024                    throw new NoSuchEmailAddressException(msg.toString());
3025            }
3026    
3027            /**
3028             * Returns the first email address in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
3029             *
3030             * @param companyId the company ID
3031             * @param classNameId the class name ID
3032             * @param classPK the class p k
3033             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3034             * @return the first matching email address, or <code>null</code> if a matching email address could not be found
3035             */
3036            @Override
3037            public EmailAddress fetchByC_C_C_First(long companyId, long classNameId,
3038                    long classPK, OrderByComparator<EmailAddress> orderByComparator) {
3039                    List<EmailAddress> list = findByC_C_C(companyId, classNameId, classPK,
3040                                    0, 1, orderByComparator);
3041    
3042                    if (!list.isEmpty()) {
3043                            return list.get(0);
3044                    }
3045    
3046                    return null;
3047            }
3048    
3049            /**
3050             * Returns the last email address in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
3051             *
3052             * @param companyId the company ID
3053             * @param classNameId the class name ID
3054             * @param classPK the class p k
3055             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3056             * @return the last matching email address
3057             * @throws NoSuchEmailAddressException if a matching email address could not be found
3058             */
3059            @Override
3060            public EmailAddress findByC_C_C_Last(long companyId, long classNameId,
3061                    long classPK, OrderByComparator<EmailAddress> orderByComparator)
3062                    throws NoSuchEmailAddressException {
3063                    EmailAddress emailAddress = fetchByC_C_C_Last(companyId, classNameId,
3064                                    classPK, orderByComparator);
3065    
3066                    if (emailAddress != null) {
3067                            return emailAddress;
3068                    }
3069    
3070                    StringBundler msg = new StringBundler(8);
3071    
3072                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3073    
3074                    msg.append("companyId=");
3075                    msg.append(companyId);
3076    
3077                    msg.append(", classNameId=");
3078                    msg.append(classNameId);
3079    
3080                    msg.append(", classPK=");
3081                    msg.append(classPK);
3082    
3083                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3084    
3085                    throw new NoSuchEmailAddressException(msg.toString());
3086            }
3087    
3088            /**
3089             * Returns the last email address in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
3090             *
3091             * @param companyId the company ID
3092             * @param classNameId the class name ID
3093             * @param classPK the class p k
3094             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3095             * @return the last matching email address, or <code>null</code> if a matching email address could not be found
3096             */
3097            @Override
3098            public EmailAddress fetchByC_C_C_Last(long companyId, long classNameId,
3099                    long classPK, OrderByComparator<EmailAddress> orderByComparator) {
3100                    int count = countByC_C_C(companyId, classNameId, classPK);
3101    
3102                    if (count == 0) {
3103                            return null;
3104                    }
3105    
3106                    List<EmailAddress> list = findByC_C_C(companyId, classNameId, classPK,
3107                                    count - 1, count, orderByComparator);
3108    
3109                    if (!list.isEmpty()) {
3110                            return list.get(0);
3111                    }
3112    
3113                    return null;
3114            }
3115    
3116            /**
3117             * Returns the email addresses before and after the current email address in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
3118             *
3119             * @param emailAddressId the primary key of the current email address
3120             * @param companyId the company ID
3121             * @param classNameId the class name ID
3122             * @param classPK the class p k
3123             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3124             * @return the previous, current, and next email address
3125             * @throws NoSuchEmailAddressException if a email address with the primary key could not be found
3126             */
3127            @Override
3128            public EmailAddress[] findByC_C_C_PrevAndNext(long emailAddressId,
3129                    long companyId, long classNameId, long classPK,
3130                    OrderByComparator<EmailAddress> orderByComparator)
3131                    throws NoSuchEmailAddressException {
3132                    EmailAddress emailAddress = findByPrimaryKey(emailAddressId);
3133    
3134                    Session session = null;
3135    
3136                    try {
3137                            session = openSession();
3138    
3139                            EmailAddress[] array = new EmailAddressImpl[3];
3140    
3141                            array[0] = getByC_C_C_PrevAndNext(session, emailAddress, companyId,
3142                                            classNameId, classPK, orderByComparator, true);
3143    
3144                            array[1] = emailAddress;
3145    
3146                            array[2] = getByC_C_C_PrevAndNext(session, emailAddress, companyId,
3147                                            classNameId, classPK, orderByComparator, false);
3148    
3149                            return array;
3150                    }
3151                    catch (Exception e) {
3152                            throw processException(e);
3153                    }
3154                    finally {
3155                            closeSession(session);
3156                    }
3157            }
3158    
3159            protected EmailAddress getByC_C_C_PrevAndNext(Session session,
3160                    EmailAddress emailAddress, long companyId, long classNameId,
3161                    long classPK, OrderByComparator<EmailAddress> orderByComparator,
3162                    boolean previous) {
3163                    StringBundler query = null;
3164    
3165                    if (orderByComparator != null) {
3166                            query = new StringBundler(6 +
3167                                            (orderByComparator.getOrderByFields().length * 6));
3168                    }
3169                    else {
3170                            query = new StringBundler(3);
3171                    }
3172    
3173                    query.append(_SQL_SELECT_EMAILADDRESS_WHERE);
3174    
3175                    query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
3176    
3177                    query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
3178    
3179                    query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
3180    
3181                    if (orderByComparator != null) {
3182                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3183    
3184                            if (orderByConditionFields.length > 0) {
3185                                    query.append(WHERE_AND);
3186                            }
3187    
3188                            for (int i = 0; i < orderByConditionFields.length; i++) {
3189                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3190                                    query.append(orderByConditionFields[i]);
3191    
3192                                    if ((i + 1) < orderByConditionFields.length) {
3193                                            if (orderByComparator.isAscending() ^ previous) {
3194                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3195                                            }
3196                                            else {
3197                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3198                                            }
3199                                    }
3200                                    else {
3201                                            if (orderByComparator.isAscending() ^ previous) {
3202                                                    query.append(WHERE_GREATER_THAN);
3203                                            }
3204                                            else {
3205                                                    query.append(WHERE_LESSER_THAN);
3206                                            }
3207                                    }
3208                            }
3209    
3210                            query.append(ORDER_BY_CLAUSE);
3211    
3212                            String[] orderByFields = orderByComparator.getOrderByFields();
3213    
3214                            for (int i = 0; i < orderByFields.length; i++) {
3215                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3216                                    query.append(orderByFields[i]);
3217    
3218                                    if ((i + 1) < orderByFields.length) {
3219                                            if (orderByComparator.isAscending() ^ previous) {
3220                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3221                                            }
3222                                            else {
3223                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3224                                            }
3225                                    }
3226                                    else {
3227                                            if (orderByComparator.isAscending() ^ previous) {
3228                                                    query.append(ORDER_BY_ASC);
3229                                            }
3230                                            else {
3231                                                    query.append(ORDER_BY_DESC);
3232                                            }
3233                                    }
3234                            }
3235                    }
3236                    else {
3237                            query.append(EmailAddressModelImpl.ORDER_BY_JPQL);
3238                    }
3239    
3240                    String sql = query.toString();
3241    
3242                    Query q = session.createQuery(sql);
3243    
3244                    q.setFirstResult(0);
3245                    q.setMaxResults(2);
3246    
3247                    QueryPos qPos = QueryPos.getInstance(q);
3248    
3249                    qPos.add(companyId);
3250    
3251                    qPos.add(classNameId);
3252    
3253                    qPos.add(classPK);
3254    
3255                    if (orderByComparator != null) {
3256                            Object[] values = orderByComparator.getOrderByConditionValues(emailAddress);
3257    
3258                            for (Object value : values) {
3259                                    qPos.add(value);
3260                            }
3261                    }
3262    
3263                    List<EmailAddress> list = q.list();
3264    
3265                    if (list.size() == 2) {
3266                            return list.get(1);
3267                    }
3268                    else {
3269                            return null;
3270                    }
3271            }
3272    
3273            /**
3274             * Removes all the email addresses where companyId = &#63; and classNameId = &#63; and classPK = &#63; from the database.
3275             *
3276             * @param companyId the company ID
3277             * @param classNameId the class name ID
3278             * @param classPK the class p k
3279             */
3280            @Override
3281            public void removeByC_C_C(long companyId, long classNameId, long classPK) {
3282                    for (EmailAddress emailAddress : findByC_C_C(companyId, classNameId,
3283                                    classPK, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3284                            remove(emailAddress);
3285                    }
3286            }
3287    
3288            /**
3289             * Returns the number of email addresses where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
3290             *
3291             * @param companyId the company ID
3292             * @param classNameId the class name ID
3293             * @param classPK the class p k
3294             * @return the number of matching email addresses
3295             */
3296            @Override
3297            public int countByC_C_C(long companyId, long classNameId, long classPK) {
3298                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C_C;
3299    
3300                    Object[] finderArgs = new Object[] { companyId, classNameId, classPK };
3301    
3302                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
3303    
3304                    if (count == null) {
3305                            StringBundler query = new StringBundler(4);
3306    
3307                            query.append(_SQL_COUNT_EMAILADDRESS_WHERE);
3308    
3309                            query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
3310    
3311                            query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
3312    
3313                            query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
3314    
3315                            String sql = query.toString();
3316    
3317                            Session session = null;
3318    
3319                            try {
3320                                    session = openSession();
3321    
3322                                    Query q = session.createQuery(sql);
3323    
3324                                    QueryPos qPos = QueryPos.getInstance(q);
3325    
3326                                    qPos.add(companyId);
3327    
3328                                    qPos.add(classNameId);
3329    
3330                                    qPos.add(classPK);
3331    
3332                                    count = (Long)q.uniqueResult();
3333    
3334                                    finderCache.putResult(finderPath, finderArgs, count);
3335                            }
3336                            catch (Exception e) {
3337                                    finderCache.removeResult(finderPath, finderArgs);
3338    
3339                                    throw processException(e);
3340                            }
3341                            finally {
3342                                    closeSession(session);
3343                            }
3344                    }
3345    
3346                    return count.intValue();
3347            }
3348    
3349            private static final String _FINDER_COLUMN_C_C_C_COMPANYID_2 = "emailAddress.companyId = ? AND ";
3350            private static final String _FINDER_COLUMN_C_C_C_CLASSNAMEID_2 = "emailAddress.classNameId = ? AND ";
3351            private static final String _FINDER_COLUMN_C_C_C_CLASSPK_2 = "emailAddress.classPK = ?";
3352            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_C_P = new FinderPath(EmailAddressModelImpl.ENTITY_CACHE_ENABLED,
3353                            EmailAddressModelImpl.FINDER_CACHE_ENABLED, EmailAddressImpl.class,
3354                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C_C_P",
3355                            new String[] {
3356                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
3357                                    Boolean.class.getName(),
3358                                    
3359                            Integer.class.getName(), Integer.class.getName(),
3360                                    OrderByComparator.class.getName()
3361                            });
3362            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C_P =
3363                    new FinderPath(EmailAddressModelImpl.ENTITY_CACHE_ENABLED,
3364                            EmailAddressModelImpl.FINDER_CACHE_ENABLED, EmailAddressImpl.class,
3365                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C_C_P",
3366                            new String[] {
3367                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
3368                                    Boolean.class.getName()
3369                            },
3370                            EmailAddressModelImpl.COMPANYID_COLUMN_BITMASK |
3371                            EmailAddressModelImpl.CLASSNAMEID_COLUMN_BITMASK |
3372                            EmailAddressModelImpl.CLASSPK_COLUMN_BITMASK |
3373                            EmailAddressModelImpl.PRIMARY_COLUMN_BITMASK |
3374                            EmailAddressModelImpl.CREATEDATE_COLUMN_BITMASK);
3375            public static final FinderPath FINDER_PATH_COUNT_BY_C_C_C_P = new FinderPath(EmailAddressModelImpl.ENTITY_CACHE_ENABLED,
3376                            EmailAddressModelImpl.FINDER_CACHE_ENABLED, Long.class,
3377                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_C_P",
3378                            new String[] {
3379                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
3380                                    Boolean.class.getName()
3381                            });
3382    
3383            /**
3384             * Returns all the email addresses where companyId = &#63; and classNameId = &#63; and classPK = &#63; and primary = &#63;.
3385             *
3386             * @param companyId the company ID
3387             * @param classNameId the class name ID
3388             * @param classPK the class p k
3389             * @param primary the primary
3390             * @return the matching email addresses
3391             */
3392            @Override
3393            public List<EmailAddress> findByC_C_C_P(long companyId, long classNameId,
3394                    long classPK, boolean primary) {
3395                    return findByC_C_C_P(companyId, classNameId, classPK, primary,
3396                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3397            }
3398    
3399            /**
3400             * Returns a range of all the email addresses where companyId = &#63; and classNameId = &#63; and classPK = &#63; and primary = &#63;.
3401             *
3402             * <p>
3403             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
3404             * </p>
3405             *
3406             * @param companyId the company ID
3407             * @param classNameId the class name ID
3408             * @param classPK the class p k
3409             * @param primary the primary
3410             * @param start the lower bound of the range of email addresses
3411             * @param end the upper bound of the range of email addresses (not inclusive)
3412             * @return the range of matching email addresses
3413             */
3414            @Override
3415            public List<EmailAddress> findByC_C_C_P(long companyId, long classNameId,
3416                    long classPK, boolean primary, int start, int end) {
3417                    return findByC_C_C_P(companyId, classNameId, classPK, primary, start,
3418                            end, null);
3419            }
3420    
3421            /**
3422             * Returns an ordered range of all the email addresses where companyId = &#63; and classNameId = &#63; and classPK = &#63; and primary = &#63;.
3423             *
3424             * <p>
3425             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
3426             * </p>
3427             *
3428             * @param companyId the company ID
3429             * @param classNameId the class name ID
3430             * @param classPK the class p k
3431             * @param primary the primary
3432             * @param start the lower bound of the range of email addresses
3433             * @param end the upper bound of the range of email addresses (not inclusive)
3434             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3435             * @return the ordered range of matching email addresses
3436             */
3437            @Override
3438            public List<EmailAddress> findByC_C_C_P(long companyId, long classNameId,
3439                    long classPK, boolean primary, int start, int end,
3440                    OrderByComparator<EmailAddress> orderByComparator) {
3441                    return findByC_C_C_P(companyId, classNameId, classPK, primary, start,
3442                            end, orderByComparator, true);
3443            }
3444    
3445            /**
3446             * Returns an ordered range of all the email addresses where companyId = &#63; and classNameId = &#63; and classPK = &#63; and primary = &#63;.
3447             *
3448             * <p>
3449             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
3450             * </p>
3451             *
3452             * @param companyId the company ID
3453             * @param classNameId the class name ID
3454             * @param classPK the class p k
3455             * @param primary the primary
3456             * @param start the lower bound of the range of email addresses
3457             * @param end the upper bound of the range of email addresses (not inclusive)
3458             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3459             * @param retrieveFromCache whether to retrieve from the finder cache
3460             * @return the ordered range of matching email addresses
3461             */
3462            @Override
3463            public List<EmailAddress> findByC_C_C_P(long companyId, long classNameId,
3464                    long classPK, boolean primary, int start, int end,
3465                    OrderByComparator<EmailAddress> orderByComparator,
3466                    boolean retrieveFromCache) {
3467                    boolean pagination = true;
3468                    FinderPath finderPath = null;
3469                    Object[] finderArgs = null;
3470    
3471                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3472                                    (orderByComparator == null)) {
3473                            pagination = false;
3474                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C_P;
3475                            finderArgs = new Object[] { companyId, classNameId, classPK, primary };
3476                    }
3477                    else {
3478                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_C_P;
3479                            finderArgs = new Object[] {
3480                                            companyId, classNameId, classPK, primary,
3481                                            
3482                                            start, end, orderByComparator
3483                                    };
3484                    }
3485    
3486                    List<EmailAddress> list = null;
3487    
3488                    if (retrieveFromCache) {
3489                            list = (List<EmailAddress>)finderCache.getResult(finderPath,
3490                                            finderArgs, this);
3491    
3492                            if ((list != null) && !list.isEmpty()) {
3493                                    for (EmailAddress emailAddress : list) {
3494                                            if ((companyId != emailAddress.getCompanyId()) ||
3495                                                            (classNameId != emailAddress.getClassNameId()) ||
3496                                                            (classPK != emailAddress.getClassPK()) ||
3497                                                            (primary != emailAddress.getPrimary())) {
3498                                                    list = null;
3499    
3500                                                    break;
3501                                            }
3502                                    }
3503                            }
3504                    }
3505    
3506                    if (list == null) {
3507                            StringBundler query = null;
3508    
3509                            if (orderByComparator != null) {
3510                                    query = new StringBundler(6 +
3511                                                    (orderByComparator.getOrderByFields().length * 3));
3512                            }
3513                            else {
3514                                    query = new StringBundler(6);
3515                            }
3516    
3517                            query.append(_SQL_SELECT_EMAILADDRESS_WHERE);
3518    
3519                            query.append(_FINDER_COLUMN_C_C_C_P_COMPANYID_2);
3520    
3521                            query.append(_FINDER_COLUMN_C_C_C_P_CLASSNAMEID_2);
3522    
3523                            query.append(_FINDER_COLUMN_C_C_C_P_CLASSPK_2);
3524    
3525                            query.append(_FINDER_COLUMN_C_C_C_P_PRIMARY_2);
3526    
3527                            if (orderByComparator != null) {
3528                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3529                                            orderByComparator);
3530                            }
3531                            else
3532                             if (pagination) {
3533                                    query.append(EmailAddressModelImpl.ORDER_BY_JPQL);
3534                            }
3535    
3536                            String sql = query.toString();
3537    
3538                            Session session = null;
3539    
3540                            try {
3541                                    session = openSession();
3542    
3543                                    Query q = session.createQuery(sql);
3544    
3545                                    QueryPos qPos = QueryPos.getInstance(q);
3546    
3547                                    qPos.add(companyId);
3548    
3549                                    qPos.add(classNameId);
3550    
3551                                    qPos.add(classPK);
3552    
3553                                    qPos.add(primary);
3554    
3555                                    if (!pagination) {
3556                                            list = (List<EmailAddress>)QueryUtil.list(q, getDialect(),
3557                                                            start, end, false);
3558    
3559                                            Collections.sort(list);
3560    
3561                                            list = Collections.unmodifiableList(list);
3562                                    }
3563                                    else {
3564                                            list = (List<EmailAddress>)QueryUtil.list(q, getDialect(),
3565                                                            start, end);
3566                                    }
3567    
3568                                    cacheResult(list);
3569    
3570                                    finderCache.putResult(finderPath, finderArgs, list);
3571                            }
3572                            catch (Exception e) {
3573                                    finderCache.removeResult(finderPath, finderArgs);
3574    
3575                                    throw processException(e);
3576                            }
3577                            finally {
3578                                    closeSession(session);
3579                            }
3580                    }
3581    
3582                    return list;
3583            }
3584    
3585            /**
3586             * Returns the first email address in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63; and primary = &#63;.
3587             *
3588             * @param companyId the company ID
3589             * @param classNameId the class name ID
3590             * @param classPK the class p k
3591             * @param primary the primary
3592             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3593             * @return the first matching email address
3594             * @throws NoSuchEmailAddressException if a matching email address could not be found
3595             */
3596            @Override
3597            public EmailAddress findByC_C_C_P_First(long companyId, long classNameId,
3598                    long classPK, boolean primary,
3599                    OrderByComparator<EmailAddress> orderByComparator)
3600                    throws NoSuchEmailAddressException {
3601                    EmailAddress emailAddress = fetchByC_C_C_P_First(companyId,
3602                                    classNameId, classPK, primary, orderByComparator);
3603    
3604                    if (emailAddress != null) {
3605                            return emailAddress;
3606                    }
3607    
3608                    StringBundler msg = new StringBundler(10);
3609    
3610                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3611    
3612                    msg.append("companyId=");
3613                    msg.append(companyId);
3614    
3615                    msg.append(", classNameId=");
3616                    msg.append(classNameId);
3617    
3618                    msg.append(", classPK=");
3619                    msg.append(classPK);
3620    
3621                    msg.append(", primary=");
3622                    msg.append(primary);
3623    
3624                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3625    
3626                    throw new NoSuchEmailAddressException(msg.toString());
3627            }
3628    
3629            /**
3630             * Returns the first email address in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63; and primary = &#63;.
3631             *
3632             * @param companyId the company ID
3633             * @param classNameId the class name ID
3634             * @param classPK the class p k
3635             * @param primary the primary
3636             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3637             * @return the first matching email address, or <code>null</code> if a matching email address could not be found
3638             */
3639            @Override
3640            public EmailAddress fetchByC_C_C_P_First(long companyId, long classNameId,
3641                    long classPK, boolean primary,
3642                    OrderByComparator<EmailAddress> orderByComparator) {
3643                    List<EmailAddress> list = findByC_C_C_P(companyId, classNameId,
3644                                    classPK, primary, 0, 1, orderByComparator);
3645    
3646                    if (!list.isEmpty()) {
3647                            return list.get(0);
3648                    }
3649    
3650                    return null;
3651            }
3652    
3653            /**
3654             * Returns the last email address in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63; and primary = &#63;.
3655             *
3656             * @param companyId the company ID
3657             * @param classNameId the class name ID
3658             * @param classPK the class p k
3659             * @param primary the primary
3660             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3661             * @return the last matching email address
3662             * @throws NoSuchEmailAddressException if a matching email address could not be found
3663             */
3664            @Override
3665            public EmailAddress findByC_C_C_P_Last(long companyId, long classNameId,
3666                    long classPK, boolean primary,
3667                    OrderByComparator<EmailAddress> orderByComparator)
3668                    throws NoSuchEmailAddressException {
3669                    EmailAddress emailAddress = fetchByC_C_C_P_Last(companyId, classNameId,
3670                                    classPK, primary, orderByComparator);
3671    
3672                    if (emailAddress != null) {
3673                            return emailAddress;
3674                    }
3675    
3676                    StringBundler msg = new StringBundler(10);
3677    
3678                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3679    
3680                    msg.append("companyId=");
3681                    msg.append(companyId);
3682    
3683                    msg.append(", classNameId=");
3684                    msg.append(classNameId);
3685    
3686                    msg.append(", classPK=");
3687                    msg.append(classPK);
3688    
3689                    msg.append(", primary=");
3690                    msg.append(primary);
3691    
3692                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3693    
3694                    throw new NoSuchEmailAddressException(msg.toString());
3695            }
3696    
3697            /**
3698             * Returns the last email address in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63; and primary = &#63;.
3699             *
3700             * @param companyId the company ID
3701             * @param classNameId the class name ID
3702             * @param classPK the class p k
3703             * @param primary the primary
3704             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3705             * @return the last matching email address, or <code>null</code> if a matching email address could not be found
3706             */
3707            @Override
3708            public EmailAddress fetchByC_C_C_P_Last(long companyId, long classNameId,
3709                    long classPK, boolean primary,
3710                    OrderByComparator<EmailAddress> orderByComparator) {
3711                    int count = countByC_C_C_P(companyId, classNameId, classPK, primary);
3712    
3713                    if (count == 0) {
3714                            return null;
3715                    }
3716    
3717                    List<EmailAddress> list = findByC_C_C_P(companyId, classNameId,
3718                                    classPK, primary, count - 1, count, orderByComparator);
3719    
3720                    if (!list.isEmpty()) {
3721                            return list.get(0);
3722                    }
3723    
3724                    return null;
3725            }
3726    
3727            /**
3728             * 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;.
3729             *
3730             * @param emailAddressId the primary key of the current email address
3731             * @param companyId the company ID
3732             * @param classNameId the class name ID
3733             * @param classPK the class p k
3734             * @param primary the primary
3735             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3736             * @return the previous, current, and next email address
3737             * @throws NoSuchEmailAddressException if a email address with the primary key could not be found
3738             */
3739            @Override
3740            public EmailAddress[] findByC_C_C_P_PrevAndNext(long emailAddressId,
3741                    long companyId, long classNameId, long classPK, boolean primary,
3742                    OrderByComparator<EmailAddress> orderByComparator)
3743                    throws NoSuchEmailAddressException {
3744                    EmailAddress emailAddress = findByPrimaryKey(emailAddressId);
3745    
3746                    Session session = null;
3747    
3748                    try {
3749                            session = openSession();
3750    
3751                            EmailAddress[] array = new EmailAddressImpl[3];
3752    
3753                            array[0] = getByC_C_C_P_PrevAndNext(session, emailAddress,
3754                                            companyId, classNameId, classPK, primary,
3755                                            orderByComparator, true);
3756    
3757                            array[1] = emailAddress;
3758    
3759                            array[2] = getByC_C_C_P_PrevAndNext(session, emailAddress,
3760                                            companyId, classNameId, classPK, primary,
3761                                            orderByComparator, false);
3762    
3763                            return array;
3764                    }
3765                    catch (Exception e) {
3766                            throw processException(e);
3767                    }
3768                    finally {
3769                            closeSession(session);
3770                    }
3771            }
3772    
3773            protected EmailAddress getByC_C_C_P_PrevAndNext(Session session,
3774                    EmailAddress emailAddress, long companyId, long classNameId,
3775                    long classPK, boolean primary,
3776                    OrderByComparator<EmailAddress> orderByComparator, boolean previous) {
3777                    StringBundler query = null;
3778    
3779                    if (orderByComparator != null) {
3780                            query = new StringBundler(6 +
3781                                            (orderByComparator.getOrderByFields().length * 6));
3782                    }
3783                    else {
3784                            query = new StringBundler(3);
3785                    }
3786    
3787                    query.append(_SQL_SELECT_EMAILADDRESS_WHERE);
3788    
3789                    query.append(_FINDER_COLUMN_C_C_C_P_COMPANYID_2);
3790    
3791                    query.append(_FINDER_COLUMN_C_C_C_P_CLASSNAMEID_2);
3792    
3793                    query.append(_FINDER_COLUMN_C_C_C_P_CLASSPK_2);
3794    
3795                    query.append(_FINDER_COLUMN_C_C_C_P_PRIMARY_2);
3796    
3797                    if (orderByComparator != null) {
3798                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3799    
3800                            if (orderByConditionFields.length > 0) {
3801                                    query.append(WHERE_AND);
3802                            }
3803    
3804                            for (int i = 0; i < orderByConditionFields.length; i++) {
3805                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3806                                    query.append(orderByConditionFields[i]);
3807    
3808                                    if ((i + 1) < orderByConditionFields.length) {
3809                                            if (orderByComparator.isAscending() ^ previous) {
3810                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3811                                            }
3812                                            else {
3813                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3814                                            }
3815                                    }
3816                                    else {
3817                                            if (orderByComparator.isAscending() ^ previous) {
3818                                                    query.append(WHERE_GREATER_THAN);
3819                                            }
3820                                            else {
3821                                                    query.append(WHERE_LESSER_THAN);
3822                                            }
3823                                    }
3824                            }
3825    
3826                            query.append(ORDER_BY_CLAUSE);
3827    
3828                            String[] orderByFields = orderByComparator.getOrderByFields();
3829    
3830                            for (int i = 0; i < orderByFields.length; i++) {
3831                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3832                                    query.append(orderByFields[i]);
3833    
3834                                    if ((i + 1) < orderByFields.length) {
3835                                            if (orderByComparator.isAscending() ^ previous) {
3836                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3837                                            }
3838                                            else {
3839                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3840                                            }
3841                                    }
3842                                    else {
3843                                            if (orderByComparator.isAscending() ^ previous) {
3844                                                    query.append(ORDER_BY_ASC);
3845                                            }
3846                                            else {
3847                                                    query.append(ORDER_BY_DESC);
3848                                            }
3849                                    }
3850                            }
3851                    }
3852                    else {
3853                            query.append(EmailAddressModelImpl.ORDER_BY_JPQL);
3854                    }
3855    
3856                    String sql = query.toString();
3857    
3858                    Query q = session.createQuery(sql);
3859    
3860                    q.setFirstResult(0);
3861                    q.setMaxResults(2);
3862    
3863                    QueryPos qPos = QueryPos.getInstance(q);
3864    
3865                    qPos.add(companyId);
3866    
3867                    qPos.add(classNameId);
3868    
3869                    qPos.add(classPK);
3870    
3871                    qPos.add(primary);
3872    
3873                    if (orderByComparator != null) {
3874                            Object[] values = orderByComparator.getOrderByConditionValues(emailAddress);
3875    
3876                            for (Object value : values) {
3877                                    qPos.add(value);
3878                            }
3879                    }
3880    
3881                    List<EmailAddress> list = q.list();
3882    
3883                    if (list.size() == 2) {
3884                            return list.get(1);
3885                    }
3886                    else {
3887                            return null;
3888                    }
3889            }
3890    
3891            /**
3892             * Removes all the email addresses where companyId = &#63; and classNameId = &#63; and classPK = &#63; and primary = &#63; from the database.
3893             *
3894             * @param companyId the company ID
3895             * @param classNameId the class name ID
3896             * @param classPK the class p k
3897             * @param primary the primary
3898             */
3899            @Override
3900            public void removeByC_C_C_P(long companyId, long classNameId, long classPK,
3901                    boolean primary) {
3902                    for (EmailAddress emailAddress : findByC_C_C_P(companyId, classNameId,
3903                                    classPK, primary, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3904                            remove(emailAddress);
3905                    }
3906            }
3907    
3908            /**
3909             * Returns the number of email addresses where companyId = &#63; and classNameId = &#63; and classPK = &#63; and primary = &#63;.
3910             *
3911             * @param companyId the company ID
3912             * @param classNameId the class name ID
3913             * @param classPK the class p k
3914             * @param primary the primary
3915             * @return the number of matching email addresses
3916             */
3917            @Override
3918            public int countByC_C_C_P(long companyId, long classNameId, long classPK,
3919                    boolean primary) {
3920                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C_C_P;
3921    
3922                    Object[] finderArgs = new Object[] {
3923                                    companyId, classNameId, classPK, primary
3924                            };
3925    
3926                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
3927    
3928                    if (count == null) {
3929                            StringBundler query = new StringBundler(5);
3930    
3931                            query.append(_SQL_COUNT_EMAILADDRESS_WHERE);
3932    
3933                            query.append(_FINDER_COLUMN_C_C_C_P_COMPANYID_2);
3934    
3935                            query.append(_FINDER_COLUMN_C_C_C_P_CLASSNAMEID_2);
3936    
3937                            query.append(_FINDER_COLUMN_C_C_C_P_CLASSPK_2);
3938    
3939                            query.append(_FINDER_COLUMN_C_C_C_P_PRIMARY_2);
3940    
3941                            String sql = query.toString();
3942    
3943                            Session session = null;
3944    
3945                            try {
3946                                    session = openSession();
3947    
3948                                    Query q = session.createQuery(sql);
3949    
3950                                    QueryPos qPos = QueryPos.getInstance(q);
3951    
3952                                    qPos.add(companyId);
3953    
3954                                    qPos.add(classNameId);
3955    
3956                                    qPos.add(classPK);
3957    
3958                                    qPos.add(primary);
3959    
3960                                    count = (Long)q.uniqueResult();
3961    
3962                                    finderCache.putResult(finderPath, finderArgs, count);
3963                            }
3964                            catch (Exception e) {
3965                                    finderCache.removeResult(finderPath, finderArgs);
3966    
3967                                    throw processException(e);
3968                            }
3969                            finally {
3970                                    closeSession(session);
3971                            }
3972                    }
3973    
3974                    return count.intValue();
3975            }
3976    
3977            private static final String _FINDER_COLUMN_C_C_C_P_COMPANYID_2 = "emailAddress.companyId = ? AND ";
3978            private static final String _FINDER_COLUMN_C_C_C_P_CLASSNAMEID_2 = "emailAddress.classNameId = ? AND ";
3979            private static final String _FINDER_COLUMN_C_C_C_P_CLASSPK_2 = "emailAddress.classPK = ? AND ";
3980            private static final String _FINDER_COLUMN_C_C_C_P_PRIMARY_2 = "emailAddress.primary = ?";
3981    
3982            public EmailAddressPersistenceImpl() {
3983                    setModelClass(EmailAddress.class);
3984            }
3985    
3986            /**
3987             * Caches the email address in the entity cache if it is enabled.
3988             *
3989             * @param emailAddress the email address
3990             */
3991            @Override
3992            public void cacheResult(EmailAddress emailAddress) {
3993                    entityCache.putResult(EmailAddressModelImpl.ENTITY_CACHE_ENABLED,
3994                            EmailAddressImpl.class, emailAddress.getPrimaryKey(), emailAddress);
3995    
3996                    emailAddress.resetOriginalValues();
3997            }
3998    
3999            /**
4000             * Caches the email addresses in the entity cache if it is enabled.
4001             *
4002             * @param emailAddresses the email addresses
4003             */
4004            @Override
4005            public void cacheResult(List<EmailAddress> emailAddresses) {
4006                    for (EmailAddress emailAddress : emailAddresses) {
4007                            if (entityCache.getResult(
4008                                                    EmailAddressModelImpl.ENTITY_CACHE_ENABLED,
4009                                                    EmailAddressImpl.class, emailAddress.getPrimaryKey()) == null) {
4010                                    cacheResult(emailAddress);
4011                            }
4012                            else {
4013                                    emailAddress.resetOriginalValues();
4014                            }
4015                    }
4016            }
4017    
4018            /**
4019             * Clears the cache for all email addresses.
4020             *
4021             * <p>
4022             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
4023             * </p>
4024             */
4025            @Override
4026            public void clearCache() {
4027                    entityCache.clearCache(EmailAddressImpl.class);
4028    
4029                    finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
4030                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4031                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4032            }
4033    
4034            /**
4035             * Clears the cache for the email address.
4036             *
4037             * <p>
4038             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
4039             * </p>
4040             */
4041            @Override
4042            public void clearCache(EmailAddress emailAddress) {
4043                    entityCache.removeResult(EmailAddressModelImpl.ENTITY_CACHE_ENABLED,
4044                            EmailAddressImpl.class, emailAddress.getPrimaryKey());
4045    
4046                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4047                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4048            }
4049    
4050            @Override
4051            public void clearCache(List<EmailAddress> emailAddresses) {
4052                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4053                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4054    
4055                    for (EmailAddress emailAddress : emailAddresses) {
4056                            entityCache.removeResult(EmailAddressModelImpl.ENTITY_CACHE_ENABLED,
4057                                    EmailAddressImpl.class, emailAddress.getPrimaryKey());
4058                    }
4059            }
4060    
4061            /**
4062             * Creates a new email address with the primary key. Does not add the email address to the database.
4063             *
4064             * @param emailAddressId the primary key for the new email address
4065             * @return the new email address
4066             */
4067            @Override
4068            public EmailAddress create(long emailAddressId) {
4069                    EmailAddress emailAddress = new EmailAddressImpl();
4070    
4071                    emailAddress.setNew(true);
4072                    emailAddress.setPrimaryKey(emailAddressId);
4073    
4074                    String uuid = PortalUUIDUtil.generate();
4075    
4076                    emailAddress.setUuid(uuid);
4077    
4078                    return emailAddress;
4079            }
4080    
4081            /**
4082             * Removes the email address with the primary key from the database. Also notifies the appropriate model listeners.
4083             *
4084             * @param emailAddressId the primary key of the email address
4085             * @return the email address that was removed
4086             * @throws NoSuchEmailAddressException if a email address with the primary key could not be found
4087             */
4088            @Override
4089            public EmailAddress remove(long emailAddressId)
4090                    throws NoSuchEmailAddressException {
4091                    return remove((Serializable)emailAddressId);
4092            }
4093    
4094            /**
4095             * Removes the email address with the primary key from the database. Also notifies the appropriate model listeners.
4096             *
4097             * @param primaryKey the primary key of the email address
4098             * @return the email address that was removed
4099             * @throws NoSuchEmailAddressException if a email address with the primary key could not be found
4100             */
4101            @Override
4102            public EmailAddress remove(Serializable primaryKey)
4103                    throws NoSuchEmailAddressException {
4104                    Session session = null;
4105    
4106                    try {
4107                            session = openSession();
4108    
4109                            EmailAddress emailAddress = (EmailAddress)session.get(EmailAddressImpl.class,
4110                                            primaryKey);
4111    
4112                            if (emailAddress == null) {
4113                                    if (_log.isWarnEnabled()) {
4114                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
4115                                    }
4116    
4117                                    throw new NoSuchEmailAddressException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
4118                                            primaryKey);
4119                            }
4120    
4121                            return remove(emailAddress);
4122                    }
4123                    catch (NoSuchEmailAddressException nsee) {
4124                            throw nsee;
4125                    }
4126                    catch (Exception e) {
4127                            throw processException(e);
4128                    }
4129                    finally {
4130                            closeSession(session);
4131                    }
4132            }
4133    
4134            @Override
4135            protected EmailAddress removeImpl(EmailAddress emailAddress) {
4136                    emailAddress = toUnwrappedModel(emailAddress);
4137    
4138                    Session session = null;
4139    
4140                    try {
4141                            session = openSession();
4142    
4143                            if (!session.contains(emailAddress)) {
4144                                    emailAddress = (EmailAddress)session.get(EmailAddressImpl.class,
4145                                                    emailAddress.getPrimaryKeyObj());
4146                            }
4147    
4148                            if (emailAddress != null) {
4149                                    session.delete(emailAddress);
4150                            }
4151                    }
4152                    catch (Exception e) {
4153                            throw processException(e);
4154                    }
4155                    finally {
4156                            closeSession(session);
4157                    }
4158    
4159                    if (emailAddress != null) {
4160                            clearCache(emailAddress);
4161                    }
4162    
4163                    return emailAddress;
4164            }
4165    
4166            @Override
4167            public EmailAddress updateImpl(EmailAddress emailAddress) {
4168                    emailAddress = toUnwrappedModel(emailAddress);
4169    
4170                    boolean isNew = emailAddress.isNew();
4171    
4172                    EmailAddressModelImpl emailAddressModelImpl = (EmailAddressModelImpl)emailAddress;
4173    
4174                    if (Validator.isNull(emailAddress.getUuid())) {
4175                            String uuid = PortalUUIDUtil.generate();
4176    
4177                            emailAddress.setUuid(uuid);
4178                    }
4179    
4180                    ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();
4181    
4182                    Date now = new Date();
4183    
4184                    if (isNew && (emailAddress.getCreateDate() == null)) {
4185                            if (serviceContext == null) {
4186                                    emailAddress.setCreateDate(now);
4187                            }
4188                            else {
4189                                    emailAddress.setCreateDate(serviceContext.getCreateDate(now));
4190                            }
4191                    }
4192    
4193                    if (!emailAddressModelImpl.hasSetModifiedDate()) {
4194                            if (serviceContext == null) {
4195                                    emailAddress.setModifiedDate(now);
4196                            }
4197                            else {
4198                                    emailAddress.setModifiedDate(serviceContext.getModifiedDate(now));
4199                            }
4200                    }
4201    
4202                    Session session = null;
4203    
4204                    try {
4205                            session = openSession();
4206    
4207                            if (emailAddress.isNew()) {
4208                                    session.save(emailAddress);
4209    
4210                                    emailAddress.setNew(false);
4211                            }
4212                            else {
4213                                    emailAddress = (EmailAddress)session.merge(emailAddress);
4214                            }
4215                    }
4216                    catch (Exception e) {
4217                            throw processException(e);
4218                    }
4219                    finally {
4220                            closeSession(session);
4221                    }
4222    
4223                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4224    
4225                    if (isNew || !EmailAddressModelImpl.COLUMN_BITMASK_ENABLED) {
4226                            finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4227                    }
4228    
4229                    else {
4230                            if ((emailAddressModelImpl.getColumnBitmask() &
4231                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
4232                                    Object[] args = new Object[] {
4233                                                    emailAddressModelImpl.getOriginalUuid()
4234                                            };
4235    
4236                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
4237                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
4238                                            args);
4239    
4240                                    args = new Object[] { emailAddressModelImpl.getUuid() };
4241    
4242                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
4243                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
4244                                            args);
4245                            }
4246    
4247                            if ((emailAddressModelImpl.getColumnBitmask() &
4248                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
4249                                    Object[] args = new Object[] {
4250                                                    emailAddressModelImpl.getOriginalUuid(),
4251                                                    emailAddressModelImpl.getOriginalCompanyId()
4252                                            };
4253    
4254                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
4255                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
4256                                            args);
4257    
4258                                    args = new Object[] {
4259                                                    emailAddressModelImpl.getUuid(),
4260                                                    emailAddressModelImpl.getCompanyId()
4261                                            };
4262    
4263                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
4264                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
4265                                            args);
4266                            }
4267    
4268                            if ((emailAddressModelImpl.getColumnBitmask() &
4269                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
4270                                    Object[] args = new Object[] {
4271                                                    emailAddressModelImpl.getOriginalCompanyId()
4272                                            };
4273    
4274                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_COMPANYID, args);
4275                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
4276                                            args);
4277    
4278                                    args = new Object[] { emailAddressModelImpl.getCompanyId() };
4279    
4280                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_COMPANYID, args);
4281                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
4282                                            args);
4283                            }
4284    
4285                            if ((emailAddressModelImpl.getColumnBitmask() &
4286                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
4287                                    Object[] args = new Object[] {
4288                                                    emailAddressModelImpl.getOriginalUserId()
4289                                            };
4290    
4291                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
4292                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
4293                                            args);
4294    
4295                                    args = new Object[] { emailAddressModelImpl.getUserId() };
4296    
4297                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
4298                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
4299                                            args);
4300                            }
4301    
4302                            if ((emailAddressModelImpl.getColumnBitmask() &
4303                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C.getColumnBitmask()) != 0) {
4304                                    Object[] args = new Object[] {
4305                                                    emailAddressModelImpl.getOriginalCompanyId(),
4306                                                    emailAddressModelImpl.getOriginalClassNameId()
4307                                            };
4308    
4309                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
4310                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
4311                                            args);
4312    
4313                                    args = new Object[] {
4314                                                    emailAddressModelImpl.getCompanyId(),
4315                                                    emailAddressModelImpl.getClassNameId()
4316                                            };
4317    
4318                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
4319                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
4320                                            args);
4321                            }
4322    
4323                            if ((emailAddressModelImpl.getColumnBitmask() &
4324                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C.getColumnBitmask()) != 0) {
4325                                    Object[] args = new Object[] {
4326                                                    emailAddressModelImpl.getOriginalCompanyId(),
4327                                                    emailAddressModelImpl.getOriginalClassNameId(),
4328                                                    emailAddressModelImpl.getOriginalClassPK()
4329                                            };
4330    
4331                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C_C, args);
4332                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C,
4333                                            args);
4334    
4335                                    args = new Object[] {
4336                                                    emailAddressModelImpl.getCompanyId(),
4337                                                    emailAddressModelImpl.getClassNameId(),
4338                                                    emailAddressModelImpl.getClassPK()
4339                                            };
4340    
4341                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C_C, args);
4342                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C,
4343                                            args);
4344                            }
4345    
4346                            if ((emailAddressModelImpl.getColumnBitmask() &
4347                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C_P.getColumnBitmask()) != 0) {
4348                                    Object[] args = new Object[] {
4349                                                    emailAddressModelImpl.getOriginalCompanyId(),
4350                                                    emailAddressModelImpl.getOriginalClassNameId(),
4351                                                    emailAddressModelImpl.getOriginalClassPK(),
4352                                                    emailAddressModelImpl.getOriginalPrimary()
4353                                            };
4354    
4355                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C_C_P, args);
4356                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C_P,
4357                                            args);
4358    
4359                                    args = new Object[] {
4360                                                    emailAddressModelImpl.getCompanyId(),
4361                                                    emailAddressModelImpl.getClassNameId(),
4362                                                    emailAddressModelImpl.getClassPK(),
4363                                                    emailAddressModelImpl.getPrimary()
4364                                            };
4365    
4366                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C_C_P, args);
4367                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C_P,
4368                                            args);
4369                            }
4370                    }
4371    
4372                    entityCache.putResult(EmailAddressModelImpl.ENTITY_CACHE_ENABLED,
4373                            EmailAddressImpl.class, emailAddress.getPrimaryKey(), emailAddress,
4374                            false);
4375    
4376                    emailAddress.resetOriginalValues();
4377    
4378                    return emailAddress;
4379            }
4380    
4381            protected EmailAddress toUnwrappedModel(EmailAddress emailAddress) {
4382                    if (emailAddress instanceof EmailAddressImpl) {
4383                            return emailAddress;
4384                    }
4385    
4386                    EmailAddressImpl emailAddressImpl = new EmailAddressImpl();
4387    
4388                    emailAddressImpl.setNew(emailAddress.isNew());
4389                    emailAddressImpl.setPrimaryKey(emailAddress.getPrimaryKey());
4390    
4391                    emailAddressImpl.setMvccVersion(emailAddress.getMvccVersion());
4392                    emailAddressImpl.setUuid(emailAddress.getUuid());
4393                    emailAddressImpl.setEmailAddressId(emailAddress.getEmailAddressId());
4394                    emailAddressImpl.setCompanyId(emailAddress.getCompanyId());
4395                    emailAddressImpl.setUserId(emailAddress.getUserId());
4396                    emailAddressImpl.setUserName(emailAddress.getUserName());
4397                    emailAddressImpl.setCreateDate(emailAddress.getCreateDate());
4398                    emailAddressImpl.setModifiedDate(emailAddress.getModifiedDate());
4399                    emailAddressImpl.setClassNameId(emailAddress.getClassNameId());
4400                    emailAddressImpl.setClassPK(emailAddress.getClassPK());
4401                    emailAddressImpl.setAddress(emailAddress.getAddress());
4402                    emailAddressImpl.setTypeId(emailAddress.getTypeId());
4403                    emailAddressImpl.setPrimary(emailAddress.isPrimary());
4404    
4405                    return emailAddressImpl;
4406            }
4407    
4408            /**
4409             * Returns the email address with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
4410             *
4411             * @param primaryKey the primary key of the email address
4412             * @return the email address
4413             * @throws NoSuchEmailAddressException if a email address with the primary key could not be found
4414             */
4415            @Override
4416            public EmailAddress findByPrimaryKey(Serializable primaryKey)
4417                    throws NoSuchEmailAddressException {
4418                    EmailAddress emailAddress = fetchByPrimaryKey(primaryKey);
4419    
4420                    if (emailAddress == null) {
4421                            if (_log.isWarnEnabled()) {
4422                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
4423                            }
4424    
4425                            throw new NoSuchEmailAddressException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
4426                                    primaryKey);
4427                    }
4428    
4429                    return emailAddress;
4430            }
4431    
4432            /**
4433             * Returns the email address with the primary key or throws a {@link NoSuchEmailAddressException} if it could not be found.
4434             *
4435             * @param emailAddressId the primary key of the email address
4436             * @return the email address
4437             * @throws NoSuchEmailAddressException if a email address with the primary key could not be found
4438             */
4439            @Override
4440            public EmailAddress findByPrimaryKey(long emailAddressId)
4441                    throws NoSuchEmailAddressException {
4442                    return findByPrimaryKey((Serializable)emailAddressId);
4443            }
4444    
4445            /**
4446             * Returns the email address with the primary key or returns <code>null</code> if it could not be found.
4447             *
4448             * @param primaryKey the primary key of the email address
4449             * @return the email address, or <code>null</code> if a email address with the primary key could not be found
4450             */
4451            @Override
4452            public EmailAddress fetchByPrimaryKey(Serializable primaryKey) {
4453                    EmailAddress emailAddress = (EmailAddress)entityCache.getResult(EmailAddressModelImpl.ENTITY_CACHE_ENABLED,
4454                                    EmailAddressImpl.class, primaryKey);
4455    
4456                    if (emailAddress == _nullEmailAddress) {
4457                            return null;
4458                    }
4459    
4460                    if (emailAddress == null) {
4461                            Session session = null;
4462    
4463                            try {
4464                                    session = openSession();
4465    
4466                                    emailAddress = (EmailAddress)session.get(EmailAddressImpl.class,
4467                                                    primaryKey);
4468    
4469                                    if (emailAddress != null) {
4470                                            cacheResult(emailAddress);
4471                                    }
4472                                    else {
4473                                            entityCache.putResult(EmailAddressModelImpl.ENTITY_CACHE_ENABLED,
4474                                                    EmailAddressImpl.class, primaryKey, _nullEmailAddress);
4475                                    }
4476                            }
4477                            catch (Exception e) {
4478                                    entityCache.removeResult(EmailAddressModelImpl.ENTITY_CACHE_ENABLED,
4479                                            EmailAddressImpl.class, primaryKey);
4480    
4481                                    throw processException(e);
4482                            }
4483                            finally {
4484                                    closeSession(session);
4485                            }
4486                    }
4487    
4488                    return emailAddress;
4489            }
4490    
4491            /**
4492             * Returns the email address with the primary key or returns <code>null</code> if it could not be found.
4493             *
4494             * @param emailAddressId the primary key of the email address
4495             * @return the email address, or <code>null</code> if a email address with the primary key could not be found
4496             */
4497            @Override
4498            public EmailAddress fetchByPrimaryKey(long emailAddressId) {
4499                    return fetchByPrimaryKey((Serializable)emailAddressId);
4500            }
4501    
4502            @Override
4503            public Map<Serializable, EmailAddress> fetchByPrimaryKeys(
4504                    Set<Serializable> primaryKeys) {
4505                    if (primaryKeys.isEmpty()) {
4506                            return Collections.emptyMap();
4507                    }
4508    
4509                    Map<Serializable, EmailAddress> map = new HashMap<Serializable, EmailAddress>();
4510    
4511                    if (primaryKeys.size() == 1) {
4512                            Iterator<Serializable> iterator = primaryKeys.iterator();
4513    
4514                            Serializable primaryKey = iterator.next();
4515    
4516                            EmailAddress emailAddress = fetchByPrimaryKey(primaryKey);
4517    
4518                            if (emailAddress != null) {
4519                                    map.put(primaryKey, emailAddress);
4520                            }
4521    
4522                            return map;
4523                    }
4524    
4525                    Set<Serializable> uncachedPrimaryKeys = null;
4526    
4527                    for (Serializable primaryKey : primaryKeys) {
4528                            EmailAddress emailAddress = (EmailAddress)entityCache.getResult(EmailAddressModelImpl.ENTITY_CACHE_ENABLED,
4529                                            EmailAddressImpl.class, primaryKey);
4530    
4531                            if (emailAddress == null) {
4532                                    if (uncachedPrimaryKeys == null) {
4533                                            uncachedPrimaryKeys = new HashSet<Serializable>();
4534                                    }
4535    
4536                                    uncachedPrimaryKeys.add(primaryKey);
4537                            }
4538                            else {
4539                                    map.put(primaryKey, emailAddress);
4540                            }
4541                    }
4542    
4543                    if (uncachedPrimaryKeys == null) {
4544                            return map;
4545                    }
4546    
4547                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
4548                                    1);
4549    
4550                    query.append(_SQL_SELECT_EMAILADDRESS_WHERE_PKS_IN);
4551    
4552                    for (Serializable primaryKey : uncachedPrimaryKeys) {
4553                            query.append(String.valueOf(primaryKey));
4554    
4555                            query.append(StringPool.COMMA);
4556                    }
4557    
4558                    query.setIndex(query.index() - 1);
4559    
4560                    query.append(StringPool.CLOSE_PARENTHESIS);
4561    
4562                    String sql = query.toString();
4563    
4564                    Session session = null;
4565    
4566                    try {
4567                            session = openSession();
4568    
4569                            Query q = session.createQuery(sql);
4570    
4571                            for (EmailAddress emailAddress : (List<EmailAddress>)q.list()) {
4572                                    map.put(emailAddress.getPrimaryKeyObj(), emailAddress);
4573    
4574                                    cacheResult(emailAddress);
4575    
4576                                    uncachedPrimaryKeys.remove(emailAddress.getPrimaryKeyObj());
4577                            }
4578    
4579                            for (Serializable primaryKey : uncachedPrimaryKeys) {
4580                                    entityCache.putResult(EmailAddressModelImpl.ENTITY_CACHE_ENABLED,
4581                                            EmailAddressImpl.class, primaryKey, _nullEmailAddress);
4582                            }
4583                    }
4584                    catch (Exception e) {
4585                            throw processException(e);
4586                    }
4587                    finally {
4588                            closeSession(session);
4589                    }
4590    
4591                    return map;
4592            }
4593    
4594            /**
4595             * Returns all the email addresses.
4596             *
4597             * @return the email addresses
4598             */
4599            @Override
4600            public List<EmailAddress> findAll() {
4601                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
4602            }
4603    
4604            /**
4605             * Returns a range of all the email addresses.
4606             *
4607             * <p>
4608             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
4609             * </p>
4610             *
4611             * @param start the lower bound of the range of email addresses
4612             * @param end the upper bound of the range of email addresses (not inclusive)
4613             * @return the range of email addresses
4614             */
4615            @Override
4616            public List<EmailAddress> findAll(int start, int end) {
4617                    return findAll(start, end, null);
4618            }
4619    
4620            /**
4621             * Returns an ordered range of all the email addresses.
4622             *
4623             * <p>
4624             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
4625             * </p>
4626             *
4627             * @param start the lower bound of the range of email addresses
4628             * @param end the upper bound of the range of email addresses (not inclusive)
4629             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4630             * @return the ordered range of email addresses
4631             */
4632            @Override
4633            public List<EmailAddress> findAll(int start, int end,
4634                    OrderByComparator<EmailAddress> orderByComparator) {
4635                    return findAll(start, end, orderByComparator, true);
4636            }
4637    
4638            /**
4639             * Returns an ordered range of all the email addresses.
4640             *
4641             * <p>
4642             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
4643             * </p>
4644             *
4645             * @param start the lower bound of the range of email addresses
4646             * @param end the upper bound of the range of email addresses (not inclusive)
4647             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4648             * @param retrieveFromCache whether to retrieve from the finder cache
4649             * @return the ordered range of email addresses
4650             */
4651            @Override
4652            public List<EmailAddress> findAll(int start, int end,
4653                    OrderByComparator<EmailAddress> orderByComparator,
4654                    boolean retrieveFromCache) {
4655                    boolean pagination = true;
4656                    FinderPath finderPath = null;
4657                    Object[] finderArgs = null;
4658    
4659                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4660                                    (orderByComparator == null)) {
4661                            pagination = false;
4662                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
4663                            finderArgs = FINDER_ARGS_EMPTY;
4664                    }
4665                    else {
4666                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
4667                            finderArgs = new Object[] { start, end, orderByComparator };
4668                    }
4669    
4670                    List<EmailAddress> list = null;
4671    
4672                    if (retrieveFromCache) {
4673                            list = (List<EmailAddress>)finderCache.getResult(finderPath,
4674                                            finderArgs, this);
4675                    }
4676    
4677                    if (list == null) {
4678                            StringBundler query = null;
4679                            String sql = null;
4680    
4681                            if (orderByComparator != null) {
4682                                    query = new StringBundler(2 +
4683                                                    (orderByComparator.getOrderByFields().length * 3));
4684    
4685                                    query.append(_SQL_SELECT_EMAILADDRESS);
4686    
4687                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4688                                            orderByComparator);
4689    
4690                                    sql = query.toString();
4691                            }
4692                            else {
4693                                    sql = _SQL_SELECT_EMAILADDRESS;
4694    
4695                                    if (pagination) {
4696                                            sql = sql.concat(EmailAddressModelImpl.ORDER_BY_JPQL);
4697                                    }
4698                            }
4699    
4700                            Session session = null;
4701    
4702                            try {
4703                                    session = openSession();
4704    
4705                                    Query q = session.createQuery(sql);
4706    
4707                                    if (!pagination) {
4708                                            list = (List<EmailAddress>)QueryUtil.list(q, getDialect(),
4709                                                            start, end, false);
4710    
4711                                            Collections.sort(list);
4712    
4713                                            list = Collections.unmodifiableList(list);
4714                                    }
4715                                    else {
4716                                            list = (List<EmailAddress>)QueryUtil.list(q, getDialect(),
4717                                                            start, end);
4718                                    }
4719    
4720                                    cacheResult(list);
4721    
4722                                    finderCache.putResult(finderPath, finderArgs, list);
4723                            }
4724                            catch (Exception e) {
4725                                    finderCache.removeResult(finderPath, finderArgs);
4726    
4727                                    throw processException(e);
4728                            }
4729                            finally {
4730                                    closeSession(session);
4731                            }
4732                    }
4733    
4734                    return list;
4735            }
4736    
4737            /**
4738             * Removes all the email addresses from the database.
4739             *
4740             */
4741            @Override
4742            public void removeAll() {
4743                    for (EmailAddress emailAddress : findAll()) {
4744                            remove(emailAddress);
4745                    }
4746            }
4747    
4748            /**
4749             * Returns the number of email addresses.
4750             *
4751             * @return the number of email addresses
4752             */
4753            @Override
4754            public int countAll() {
4755                    Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
4756                                    FINDER_ARGS_EMPTY, this);
4757    
4758                    if (count == null) {
4759                            Session session = null;
4760    
4761                            try {
4762                                    session = openSession();
4763    
4764                                    Query q = session.createQuery(_SQL_COUNT_EMAILADDRESS);
4765    
4766                                    count = (Long)q.uniqueResult();
4767    
4768                                    finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
4769                                            count);
4770                            }
4771                            catch (Exception e) {
4772                                    finderCache.removeResult(FINDER_PATH_COUNT_ALL,
4773                                            FINDER_ARGS_EMPTY);
4774    
4775                                    throw processException(e);
4776                            }
4777                            finally {
4778                                    closeSession(session);
4779                            }
4780                    }
4781    
4782                    return count.intValue();
4783            }
4784    
4785            @Override
4786            public Set<String> getBadColumnNames() {
4787                    return _badColumnNames;
4788            }
4789    
4790            @Override
4791            protected Map<String, Integer> getTableColumnsMap() {
4792                    return EmailAddressModelImpl.TABLE_COLUMNS_MAP;
4793            }
4794    
4795            /**
4796             * Initializes the email address persistence.
4797             */
4798            public void afterPropertiesSet() {
4799            }
4800    
4801            public void destroy() {
4802                    entityCache.removeCache(EmailAddressImpl.class.getName());
4803                    finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
4804                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4805                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4806            }
4807    
4808            @BeanReference(type = CompanyProvider.class)
4809            protected CompanyProvider companyProvider;
4810            protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
4811            protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
4812            private static final String _SQL_SELECT_EMAILADDRESS = "SELECT emailAddress FROM EmailAddress emailAddress";
4813            private static final String _SQL_SELECT_EMAILADDRESS_WHERE_PKS_IN = "SELECT emailAddress FROM EmailAddress emailAddress WHERE emailAddressId IN (";
4814            private static final String _SQL_SELECT_EMAILADDRESS_WHERE = "SELECT emailAddress FROM EmailAddress emailAddress WHERE ";
4815            private static final String _SQL_COUNT_EMAILADDRESS = "SELECT COUNT(emailAddress) FROM EmailAddress emailAddress";
4816            private static final String _SQL_COUNT_EMAILADDRESS_WHERE = "SELECT COUNT(emailAddress) FROM EmailAddress emailAddress WHERE ";
4817            private static final String _ORDER_BY_ENTITY_ALIAS = "emailAddress.";
4818            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No EmailAddress exists with the primary key ";
4819            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No EmailAddress exists with the key {";
4820            private static final Log _log = LogFactoryUtil.getLog(EmailAddressPersistenceImpl.class);
4821            private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
4822                                    "uuid", "primary"
4823                            });
4824            private static final EmailAddress _nullEmailAddress = new EmailAddressImpl() {
4825                            @Override
4826                            public Object clone() {
4827                                    return this;
4828                            }
4829    
4830                            @Override
4831                            public CacheModel<EmailAddress> toCacheModel() {
4832                                    return _nullEmailAddressCacheModel;
4833                            }
4834                    };
4835    
4836            private static final CacheModel<EmailAddress> _nullEmailAddressCacheModel = new NullCacheModel();
4837    
4838            private static class NullCacheModel implements CacheModel<EmailAddress>,
4839                    MVCCModel {
4840                    @Override
4841                    public long getMvccVersion() {
4842                            return -1;
4843                    }
4844    
4845                    @Override
4846                    public void setMvccVersion(long mvccVersion) {
4847                    }
4848    
4849                    @Override
4850                    public EmailAddress toEntityModel() {
4851                            return _nullEmailAddress;
4852                    }
4853            }
4854    }