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