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