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