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