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