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