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