001    /**
002     * Copyright (c) 2000-2010 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.NoSuchModelException;
019    import com.liferay.portal.kernel.annotation.BeanReference;
020    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
021    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
023    import com.liferay.portal.kernel.dao.orm.FinderPath;
024    import com.liferay.portal.kernel.dao.orm.Query;
025    import com.liferay.portal.kernel.dao.orm.QueryPos;
026    import com.liferay.portal.kernel.dao.orm.QueryUtil;
027    import com.liferay.portal.kernel.dao.orm.Session;
028    import com.liferay.portal.kernel.exception.SystemException;
029    import com.liferay.portal.kernel.log.Log;
030    import com.liferay.portal.kernel.log.LogFactoryUtil;
031    import com.liferay.portal.kernel.util.GetterUtil;
032    import com.liferay.portal.kernel.util.InstanceFactory;
033    import com.liferay.portal.kernel.util.OrderByComparator;
034    import com.liferay.portal.kernel.util.StringBundler;
035    import com.liferay.portal.kernel.util.StringPool;
036    import com.liferay.portal.kernel.util.StringUtil;
037    import com.liferay.portal.model.EmailAddress;
038    import com.liferay.portal.model.ModelListener;
039    import com.liferay.portal.model.impl.EmailAddressImpl;
040    import com.liferay.portal.model.impl.EmailAddressModelImpl;
041    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
042    
043    import java.io.Serializable;
044    
045    import java.util.ArrayList;
046    import java.util.Collections;
047    import java.util.List;
048    
049    /**
050     * The persistence implementation for the email address service.
051     *
052     * <p>
053     * 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.
054     * </p>
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            public static final String FINDER_CLASS_NAME_ENTITY = EmailAddressImpl.class.getName();
068            public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
069                    ".List";
070            public static final FinderPath FINDER_PATH_FIND_BY_COMPANYID = new FinderPath(EmailAddressModelImpl.ENTITY_CACHE_ENABLED,
071                            EmailAddressModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
072                            "findByCompanyId",
073                            new String[] {
074                                    Long.class.getName(),
075                                    
076                            "java.lang.Integer", "java.lang.Integer",
077                                    "com.liferay.portal.kernel.util.OrderByComparator"
078                            });
079            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(EmailAddressModelImpl.ENTITY_CACHE_ENABLED,
080                            EmailAddressModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
081                            "countByCompanyId", new String[] { Long.class.getName() });
082            public static final FinderPath FINDER_PATH_FIND_BY_USERID = new FinderPath(EmailAddressModelImpl.ENTITY_CACHE_ENABLED,
083                            EmailAddressModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
084                            "findByUserId",
085                            new String[] {
086                                    Long.class.getName(),
087                                    
088                            "java.lang.Integer", "java.lang.Integer",
089                                    "com.liferay.portal.kernel.util.OrderByComparator"
090                            });
091            public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(EmailAddressModelImpl.ENTITY_CACHE_ENABLED,
092                            EmailAddressModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
093                            "countByUserId", new String[] { Long.class.getName() });
094            public static final FinderPath FINDER_PATH_FIND_BY_C_C = new FinderPath(EmailAddressModelImpl.ENTITY_CACHE_ENABLED,
095                            EmailAddressModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
096                            "findByC_C",
097                            new String[] {
098                                    Long.class.getName(), Long.class.getName(),
099                                    
100                            "java.lang.Integer", "java.lang.Integer",
101                                    "com.liferay.portal.kernel.util.OrderByComparator"
102                            });
103            public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(EmailAddressModelImpl.ENTITY_CACHE_ENABLED,
104                            EmailAddressModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
105                            "countByC_C",
106                            new String[] { Long.class.getName(), Long.class.getName() });
107            public static final FinderPath FINDER_PATH_FIND_BY_C_C_C = new FinderPath(EmailAddressModelImpl.ENTITY_CACHE_ENABLED,
108                            EmailAddressModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
109                            "findByC_C_C",
110                            new String[] {
111                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
112                                    
113                            "java.lang.Integer", "java.lang.Integer",
114                                    "com.liferay.portal.kernel.util.OrderByComparator"
115                            });
116            public static final FinderPath FINDER_PATH_COUNT_BY_C_C_C = new FinderPath(EmailAddressModelImpl.ENTITY_CACHE_ENABLED,
117                            EmailAddressModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
118                            "countByC_C_C",
119                            new String[] {
120                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
121                            });
122            public static final FinderPath FINDER_PATH_FIND_BY_C_C_C_P = new FinderPath(EmailAddressModelImpl.ENTITY_CACHE_ENABLED,
123                            EmailAddressModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
124                            "findByC_C_C_P",
125                            new String[] {
126                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
127                                    Boolean.class.getName(),
128                                    
129                            "java.lang.Integer", "java.lang.Integer",
130                                    "com.liferay.portal.kernel.util.OrderByComparator"
131                            });
132            public static final FinderPath FINDER_PATH_COUNT_BY_C_C_C_P = new FinderPath(EmailAddressModelImpl.ENTITY_CACHE_ENABLED,
133                            EmailAddressModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
134                            "countByC_C_C_P",
135                            new String[] {
136                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
137                                    Boolean.class.getName()
138                            });
139            public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(EmailAddressModelImpl.ENTITY_CACHE_ENABLED,
140                            EmailAddressModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
141                            "findAll", new String[0]);
142            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(EmailAddressModelImpl.ENTITY_CACHE_ENABLED,
143                            EmailAddressModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
144                            "countAll", new String[0]);
145    
146            /**
147             * Caches the email address in the entity cache if it is enabled.
148             *
149             * @param emailAddress the email address to cache
150             */
151            public void cacheResult(EmailAddress emailAddress) {
152                    EntityCacheUtil.putResult(EmailAddressModelImpl.ENTITY_CACHE_ENABLED,
153                            EmailAddressImpl.class, emailAddress.getPrimaryKey(), emailAddress);
154            }
155    
156            /**
157             * Caches the email addresses in the entity cache if it is enabled.
158             *
159             * @param emailAddresses the email addresses to cache
160             */
161            public void cacheResult(List<EmailAddress> emailAddresses) {
162                    for (EmailAddress emailAddress : emailAddresses) {
163                            if (EntityCacheUtil.getResult(
164                                                    EmailAddressModelImpl.ENTITY_CACHE_ENABLED,
165                                                    EmailAddressImpl.class, emailAddress.getPrimaryKey(),
166                                                    this) == null) {
167                                    cacheResult(emailAddress);
168                            }
169                    }
170            }
171    
172            /**
173             * Clears the cache for all email addresses.
174             *
175             * <p>
176             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
177             * </p>
178             */
179            public void clearCache() {
180                    CacheRegistryUtil.clear(EmailAddressImpl.class.getName());
181                    EntityCacheUtil.clearCache(EmailAddressImpl.class.getName());
182                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
183                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
184            }
185    
186            /**
187             * Clears the cache for the email address.
188             *
189             * <p>
190             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
191             * </p>
192             */
193            public void clearCache(EmailAddress emailAddress) {
194                    EntityCacheUtil.removeResult(EmailAddressModelImpl.ENTITY_CACHE_ENABLED,
195                            EmailAddressImpl.class, emailAddress.getPrimaryKey());
196            }
197    
198            /**
199             * Creates a new email address with the primary key. Does not add the email address to the database.
200             *
201             * @param emailAddressId the primary key for the new email address
202             * @return the new email address
203             */
204            public EmailAddress create(long emailAddressId) {
205                    EmailAddress emailAddress = new EmailAddressImpl();
206    
207                    emailAddress.setNew(true);
208                    emailAddress.setPrimaryKey(emailAddressId);
209    
210                    return emailAddress;
211            }
212    
213            /**
214             * Removes the email address with the primary key from the database. Also notifies the appropriate model listeners.
215             *
216             * @param primaryKey the primary key of the email address to remove
217             * @return the email address that was removed
218             * @throws com.liferay.portal.NoSuchModelException if a email address with the primary key could not be found
219             * @throws SystemException if a system exception occurred
220             */
221            public EmailAddress remove(Serializable primaryKey)
222                    throws NoSuchModelException, SystemException {
223                    return remove(((Long)primaryKey).longValue());
224            }
225    
226            /**
227             * Removes the email address with the primary key from the database. Also notifies the appropriate model listeners.
228             *
229             * @param emailAddressId the primary key of the email address to remove
230             * @return the email address that was removed
231             * @throws com.liferay.portal.NoSuchEmailAddressException if a email address with the primary key could not be found
232             * @throws SystemException if a system exception occurred
233             */
234            public EmailAddress remove(long emailAddressId)
235                    throws NoSuchEmailAddressException, SystemException {
236                    Session session = null;
237    
238                    try {
239                            session = openSession();
240    
241                            EmailAddress emailAddress = (EmailAddress)session.get(EmailAddressImpl.class,
242                                            new Long(emailAddressId));
243    
244                            if (emailAddress == null) {
245                                    if (_log.isWarnEnabled()) {
246                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
247                                                    emailAddressId);
248                                    }
249    
250                                    throw new NoSuchEmailAddressException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
251                                            emailAddressId);
252                            }
253    
254                            return remove(emailAddress);
255                    }
256                    catch (NoSuchEmailAddressException nsee) {
257                            throw nsee;
258                    }
259                    catch (Exception e) {
260                            throw processException(e);
261                    }
262                    finally {
263                            closeSession(session);
264                    }
265            }
266    
267            protected EmailAddress removeImpl(EmailAddress emailAddress)
268                    throws SystemException {
269                    emailAddress = toUnwrappedModel(emailAddress);
270    
271                    Session session = null;
272    
273                    try {
274                            session = openSession();
275    
276                            if (emailAddress.isCachedModel() || BatchSessionUtil.isEnabled()) {
277                                    Object staleObject = session.get(EmailAddressImpl.class,
278                                                    emailAddress.getPrimaryKeyObj());
279    
280                                    if (staleObject != null) {
281                                            session.evict(staleObject);
282                                    }
283                            }
284    
285                            session.delete(emailAddress);
286    
287                            session.flush();
288                    }
289                    catch (Exception e) {
290                            throw processException(e);
291                    }
292                    finally {
293                            closeSession(session);
294                    }
295    
296                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
297    
298                    EntityCacheUtil.removeResult(EmailAddressModelImpl.ENTITY_CACHE_ENABLED,
299                            EmailAddressImpl.class, emailAddress.getPrimaryKey());
300    
301                    return emailAddress;
302            }
303    
304            public EmailAddress updateImpl(
305                    com.liferay.portal.model.EmailAddress emailAddress, boolean merge)
306                    throws SystemException {
307                    emailAddress = toUnwrappedModel(emailAddress);
308    
309                    Session session = null;
310    
311                    try {
312                            session = openSession();
313    
314                            BatchSessionUtil.update(session, emailAddress, merge);
315    
316                            emailAddress.setNew(false);
317                    }
318                    catch (Exception e) {
319                            throw processException(e);
320                    }
321                    finally {
322                            closeSession(session);
323                    }
324    
325                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
326    
327                    EntityCacheUtil.putResult(EmailAddressModelImpl.ENTITY_CACHE_ENABLED,
328                            EmailAddressImpl.class, emailAddress.getPrimaryKey(), emailAddress);
329    
330                    return emailAddress;
331            }
332    
333            protected EmailAddress toUnwrappedModel(EmailAddress emailAddress) {
334                    if (emailAddress instanceof EmailAddressImpl) {
335                            return emailAddress;
336                    }
337    
338                    EmailAddressImpl emailAddressImpl = new EmailAddressImpl();
339    
340                    emailAddressImpl.setNew(emailAddress.isNew());
341                    emailAddressImpl.setPrimaryKey(emailAddress.getPrimaryKey());
342    
343                    emailAddressImpl.setEmailAddressId(emailAddress.getEmailAddressId());
344                    emailAddressImpl.setCompanyId(emailAddress.getCompanyId());
345                    emailAddressImpl.setUserId(emailAddress.getUserId());
346                    emailAddressImpl.setUserName(emailAddress.getUserName());
347                    emailAddressImpl.setCreateDate(emailAddress.getCreateDate());
348                    emailAddressImpl.setModifiedDate(emailAddress.getModifiedDate());
349                    emailAddressImpl.setClassNameId(emailAddress.getClassNameId());
350                    emailAddressImpl.setClassPK(emailAddress.getClassPK());
351                    emailAddressImpl.setAddress(emailAddress.getAddress());
352                    emailAddressImpl.setTypeId(emailAddress.getTypeId());
353                    emailAddressImpl.setPrimary(emailAddress.isPrimary());
354    
355                    return emailAddressImpl;
356            }
357    
358            /**
359             * Finds the email address with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
360             *
361             * @param primaryKey the primary key of the email address to find
362             * @return the email address
363             * @throws com.liferay.portal.NoSuchModelException if a email address with the primary key could not be found
364             * @throws SystemException if a system exception occurred
365             */
366            public EmailAddress findByPrimaryKey(Serializable primaryKey)
367                    throws NoSuchModelException, SystemException {
368                    return findByPrimaryKey(((Long)primaryKey).longValue());
369            }
370    
371            /**
372             * Finds the email address with the primary key or throws a {@link com.liferay.portal.NoSuchEmailAddressException} if it could not be found.
373             *
374             * @param emailAddressId the primary key of the email address to find
375             * @return the email address
376             * @throws com.liferay.portal.NoSuchEmailAddressException if a email address with the primary key could not be found
377             * @throws SystemException if a system exception occurred
378             */
379            public EmailAddress findByPrimaryKey(long emailAddressId)
380                    throws NoSuchEmailAddressException, SystemException {
381                    EmailAddress emailAddress = fetchByPrimaryKey(emailAddressId);
382    
383                    if (emailAddress == null) {
384                            if (_log.isWarnEnabled()) {
385                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + emailAddressId);
386                            }
387    
388                            throw new NoSuchEmailAddressException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
389                                    emailAddressId);
390                    }
391    
392                    return emailAddress;
393            }
394    
395            /**
396             * Finds the email address with the primary key or returns <code>null</code> if it could not be found.
397             *
398             * @param primaryKey the primary key of the email address to find
399             * @return the email address, or <code>null</code> if a email address with the primary key could not be found
400             * @throws SystemException if a system exception occurred
401             */
402            public EmailAddress fetchByPrimaryKey(Serializable primaryKey)
403                    throws SystemException {
404                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
405            }
406    
407            /**
408             * Finds the email address with the primary key or returns <code>null</code> if it could not be found.
409             *
410             * @param emailAddressId the primary key of the email address to find
411             * @return the email address, or <code>null</code> if a email address with the primary key could not be found
412             * @throws SystemException if a system exception occurred
413             */
414            public EmailAddress fetchByPrimaryKey(long emailAddressId)
415                    throws SystemException {
416                    EmailAddress emailAddress = (EmailAddress)EntityCacheUtil.getResult(EmailAddressModelImpl.ENTITY_CACHE_ENABLED,
417                                    EmailAddressImpl.class, emailAddressId, this);
418    
419                    if (emailAddress == null) {
420                            Session session = null;
421    
422                            try {
423                                    session = openSession();
424    
425                                    emailAddress = (EmailAddress)session.get(EmailAddressImpl.class,
426                                                    new Long(emailAddressId));
427                            }
428                            catch (Exception e) {
429                                    throw processException(e);
430                            }
431                            finally {
432                                    if (emailAddress != null) {
433                                            cacheResult(emailAddress);
434                                    }
435    
436                                    closeSession(session);
437                            }
438                    }
439    
440                    return emailAddress;
441            }
442    
443            /**
444             * Finds all the email addresses where companyId = &#63;.
445             *
446             * @param companyId the company id to search with
447             * @return the matching email addresses
448             * @throws SystemException if a system exception occurred
449             */
450            public List<EmailAddress> findByCompanyId(long companyId)
451                    throws SystemException {
452                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
453                            null);
454            }
455    
456            /**
457             * Finds a range of all the email addresses where companyId = &#63;.
458             *
459             * <p>
460             * 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.
461             * </p>
462             *
463             * @param companyId the company id to search with
464             * @param start the lower bound of the range of email addresses to return
465             * @param end the upper bound of the range of email addresses to return (not inclusive)
466             * @return the range of matching email addresses
467             * @throws SystemException if a system exception occurred
468             */
469            public List<EmailAddress> findByCompanyId(long companyId, int start, int end)
470                    throws SystemException {
471                    return findByCompanyId(companyId, start, end, null);
472            }
473    
474            /**
475             * Finds an ordered range of all the email addresses where companyId = &#63;.
476             *
477             * <p>
478             * 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.
479             * </p>
480             *
481             * @param companyId the company id to search with
482             * @param start the lower bound of the range of email addresses to return
483             * @param end the upper bound of the range of email addresses to return (not inclusive)
484             * @param orderByComparator the comparator to order the results by
485             * @return the ordered range of matching email addresses
486             * @throws SystemException if a system exception occurred
487             */
488            public List<EmailAddress> findByCompanyId(long companyId, int start,
489                    int end, OrderByComparator orderByComparator) throws SystemException {
490                    Object[] finderArgs = new Object[] {
491                                    companyId,
492                                    
493                                    String.valueOf(start), String.valueOf(end),
494                                    String.valueOf(orderByComparator)
495                            };
496    
497                    List<EmailAddress> list = (List<EmailAddress>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_COMPANYID,
498                                    finderArgs, this);
499    
500                    if (list == null) {
501                            Session session = null;
502    
503                            try {
504                                    session = openSession();
505    
506                                    StringBundler query = null;
507    
508                                    if (orderByComparator != null) {
509                                            query = new StringBundler(3 +
510                                                            (orderByComparator.getOrderByFields().length * 3));
511                                    }
512                                    else {
513                                            query = new StringBundler(3);
514                                    }
515    
516                                    query.append(_SQL_SELECT_EMAILADDRESS_WHERE);
517    
518                                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
519    
520                                    if (orderByComparator != null) {
521                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
522                                                    orderByComparator);
523                                    }
524    
525                                    else {
526                                            query.append(EmailAddressModelImpl.ORDER_BY_JPQL);
527                                    }
528    
529                                    String sql = query.toString();
530    
531                                    Query q = session.createQuery(sql);
532    
533                                    QueryPos qPos = QueryPos.getInstance(q);
534    
535                                    qPos.add(companyId);
536    
537                                    list = (List<EmailAddress>)QueryUtil.list(q, getDialect(),
538                                                    start, end);
539                            }
540                            catch (Exception e) {
541                                    throw processException(e);
542                            }
543                            finally {
544                                    if (list == null) {
545                                            list = new ArrayList<EmailAddress>();
546                                    }
547    
548                                    cacheResult(list);
549    
550                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_COMPANYID,
551                                            finderArgs, list);
552    
553                                    closeSession(session);
554                            }
555                    }
556    
557                    return list;
558            }
559    
560            /**
561             * Finds the first email address in the ordered set where companyId = &#63;.
562             *
563             * <p>
564             * 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.
565             * </p>
566             *
567             * @param companyId the company id to search with
568             * @param orderByComparator the comparator to order the set by
569             * @return the first matching email address
570             * @throws com.liferay.portal.NoSuchEmailAddressException if a matching email address could not be found
571             * @throws SystemException if a system exception occurred
572             */
573            public EmailAddress findByCompanyId_First(long companyId,
574                    OrderByComparator orderByComparator)
575                    throws NoSuchEmailAddressException, SystemException {
576                    List<EmailAddress> list = findByCompanyId(companyId, 0, 1,
577                                    orderByComparator);
578    
579                    if (list.isEmpty()) {
580                            StringBundler msg = new StringBundler(4);
581    
582                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
583    
584                            msg.append("companyId=");
585                            msg.append(companyId);
586    
587                            msg.append(StringPool.CLOSE_CURLY_BRACE);
588    
589                            throw new NoSuchEmailAddressException(msg.toString());
590                    }
591                    else {
592                            return list.get(0);
593                    }
594            }
595    
596            /**
597             * Finds the last email address in the ordered set where companyId = &#63;.
598             *
599             * <p>
600             * 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.
601             * </p>
602             *
603             * @param companyId the company id to search with
604             * @param orderByComparator the comparator to order the set by
605             * @return the last matching email address
606             * @throws com.liferay.portal.NoSuchEmailAddressException if a matching email address could not be found
607             * @throws SystemException if a system exception occurred
608             */
609            public EmailAddress findByCompanyId_Last(long companyId,
610                    OrderByComparator orderByComparator)
611                    throws NoSuchEmailAddressException, SystemException {
612                    int count = countByCompanyId(companyId);
613    
614                    List<EmailAddress> list = findByCompanyId(companyId, count - 1, count,
615                                    orderByComparator);
616    
617                    if (list.isEmpty()) {
618                            StringBundler msg = new StringBundler(4);
619    
620                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
621    
622                            msg.append("companyId=");
623                            msg.append(companyId);
624    
625                            msg.append(StringPool.CLOSE_CURLY_BRACE);
626    
627                            throw new NoSuchEmailAddressException(msg.toString());
628                    }
629                    else {
630                            return list.get(0);
631                    }
632            }
633    
634            /**
635             * Finds the email addresses before and after the current email address in the ordered set where companyId = &#63;.
636             *
637             * <p>
638             * 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.
639             * </p>
640             *
641             * @param emailAddressId the primary key of the current email address
642             * @param companyId the company id to search with
643             * @param orderByComparator the comparator to order the set by
644             * @return the previous, current, and next email address
645             * @throws com.liferay.portal.NoSuchEmailAddressException if a email address with the primary key could not be found
646             * @throws SystemException if a system exception occurred
647             */
648            public EmailAddress[] findByCompanyId_PrevAndNext(long emailAddressId,
649                    long companyId, OrderByComparator orderByComparator)
650                    throws NoSuchEmailAddressException, SystemException {
651                    EmailAddress emailAddress = findByPrimaryKey(emailAddressId);
652    
653                    Session session = null;
654    
655                    try {
656                            session = openSession();
657    
658                            EmailAddress[] array = new EmailAddressImpl[3];
659    
660                            array[0] = getByCompanyId_PrevAndNext(session, emailAddress,
661                                            companyId, orderByComparator, true);
662    
663                            array[1] = emailAddress;
664    
665                            array[2] = getByCompanyId_PrevAndNext(session, emailAddress,
666                                            companyId, orderByComparator, false);
667    
668                            return array;
669                    }
670                    catch (Exception e) {
671                            throw processException(e);
672                    }
673                    finally {
674                            closeSession(session);
675                    }
676            }
677    
678            protected EmailAddress getByCompanyId_PrevAndNext(Session session,
679                    EmailAddress emailAddress, long companyId,
680                    OrderByComparator orderByComparator, boolean previous) {
681                    StringBundler query = null;
682    
683                    if (orderByComparator != null) {
684                            query = new StringBundler(6 +
685                                            (orderByComparator.getOrderByFields().length * 6));
686                    }
687                    else {
688                            query = new StringBundler(3);
689                    }
690    
691                    query.append(_SQL_SELECT_EMAILADDRESS_WHERE);
692    
693                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
694    
695                    if (orderByComparator != null) {
696                            String[] orderByFields = orderByComparator.getOrderByFields();
697    
698                            if (orderByFields.length > 0) {
699                                    query.append(WHERE_AND);
700                            }
701    
702                            for (int i = 0; i < orderByFields.length; i++) {
703                                    query.append(_ORDER_BY_ENTITY_ALIAS);
704                                    query.append(orderByFields[i]);
705    
706                                    if ((i + 1) < orderByFields.length) {
707                                            if (orderByComparator.isAscending() ^ previous) {
708                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
709                                            }
710                                            else {
711                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
712                                            }
713                                    }
714                                    else {
715                                            if (orderByComparator.isAscending() ^ previous) {
716                                                    query.append(WHERE_GREATER_THAN);
717                                            }
718                                            else {
719                                                    query.append(WHERE_LESSER_THAN);
720                                            }
721                                    }
722                            }
723    
724                            query.append(ORDER_BY_CLAUSE);
725    
726                            for (int i = 0; i < orderByFields.length; i++) {
727                                    query.append(_ORDER_BY_ENTITY_ALIAS);
728                                    query.append(orderByFields[i]);
729    
730                                    if ((i + 1) < orderByFields.length) {
731                                            if (orderByComparator.isAscending() ^ previous) {
732                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
733                                            }
734                                            else {
735                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
736                                            }
737                                    }
738                                    else {
739                                            if (orderByComparator.isAscending() ^ previous) {
740                                                    query.append(ORDER_BY_ASC);
741                                            }
742                                            else {
743                                                    query.append(ORDER_BY_DESC);
744                                            }
745                                    }
746                            }
747                    }
748    
749                    else {
750                            query.append(EmailAddressModelImpl.ORDER_BY_JPQL);
751                    }
752    
753                    String sql = query.toString();
754    
755                    Query q = session.createQuery(sql);
756    
757                    q.setFirstResult(0);
758                    q.setMaxResults(2);
759    
760                    QueryPos qPos = QueryPos.getInstance(q);
761    
762                    qPos.add(companyId);
763    
764                    if (orderByComparator != null) {
765                            Object[] values = orderByComparator.getOrderByValues(emailAddress);
766    
767                            for (Object value : values) {
768                                    qPos.add(value);
769                            }
770                    }
771    
772                    List<EmailAddress> list = q.list();
773    
774                    if (list.size() == 2) {
775                            return list.get(1);
776                    }
777                    else {
778                            return null;
779                    }
780            }
781    
782            /**
783             * Finds all the email addresses where userId = &#63;.
784             *
785             * @param userId the user id to search with
786             * @return the matching email addresses
787             * @throws SystemException if a system exception occurred
788             */
789            public List<EmailAddress> findByUserId(long userId)
790                    throws SystemException {
791                    return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
792            }
793    
794            /**
795             * Finds a range of all the email addresses where userId = &#63;.
796             *
797             * <p>
798             * 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.
799             * </p>
800             *
801             * @param userId the user id to search with
802             * @param start the lower bound of the range of email addresses to return
803             * @param end the upper bound of the range of email addresses to return (not inclusive)
804             * @return the range of matching email addresses
805             * @throws SystemException if a system exception occurred
806             */
807            public List<EmailAddress> findByUserId(long userId, int start, int end)
808                    throws SystemException {
809                    return findByUserId(userId, start, end, null);
810            }
811    
812            /**
813             * Finds an ordered range of all the email addresses where userId = &#63;.
814             *
815             * <p>
816             * 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.
817             * </p>
818             *
819             * @param userId the user id to search with
820             * @param start the lower bound of the range of email addresses to return
821             * @param end the upper bound of the range of email addresses to return (not inclusive)
822             * @param orderByComparator the comparator to order the results by
823             * @return the ordered range of matching email addresses
824             * @throws SystemException if a system exception occurred
825             */
826            public List<EmailAddress> findByUserId(long userId, int start, int end,
827                    OrderByComparator orderByComparator) throws SystemException {
828                    Object[] finderArgs = new Object[] {
829                                    userId,
830                                    
831                                    String.valueOf(start), String.valueOf(end),
832                                    String.valueOf(orderByComparator)
833                            };
834    
835                    List<EmailAddress> list = (List<EmailAddress>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_USERID,
836                                    finderArgs, this);
837    
838                    if (list == null) {
839                            Session session = null;
840    
841                            try {
842                                    session = openSession();
843    
844                                    StringBundler query = null;
845    
846                                    if (orderByComparator != null) {
847                                            query = new StringBundler(3 +
848                                                            (orderByComparator.getOrderByFields().length * 3));
849                                    }
850                                    else {
851                                            query = new StringBundler(3);
852                                    }
853    
854                                    query.append(_SQL_SELECT_EMAILADDRESS_WHERE);
855    
856                                    query.append(_FINDER_COLUMN_USERID_USERID_2);
857    
858                                    if (orderByComparator != null) {
859                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
860                                                    orderByComparator);
861                                    }
862    
863                                    else {
864                                            query.append(EmailAddressModelImpl.ORDER_BY_JPQL);
865                                    }
866    
867                                    String sql = query.toString();
868    
869                                    Query q = session.createQuery(sql);
870    
871                                    QueryPos qPos = QueryPos.getInstance(q);
872    
873                                    qPos.add(userId);
874    
875                                    list = (List<EmailAddress>)QueryUtil.list(q, getDialect(),
876                                                    start, end);
877                            }
878                            catch (Exception e) {
879                                    throw processException(e);
880                            }
881                            finally {
882                                    if (list == null) {
883                                            list = new ArrayList<EmailAddress>();
884                                    }
885    
886                                    cacheResult(list);
887    
888                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_USERID,
889                                            finderArgs, list);
890    
891                                    closeSession(session);
892                            }
893                    }
894    
895                    return list;
896            }
897    
898            /**
899             * Finds the first email address in the ordered set where userId = &#63;.
900             *
901             * <p>
902             * 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.
903             * </p>
904             *
905             * @param userId the user id to search with
906             * @param orderByComparator the comparator to order the set by
907             * @return the first matching email address
908             * @throws com.liferay.portal.NoSuchEmailAddressException if a matching email address could not be found
909             * @throws SystemException if a system exception occurred
910             */
911            public EmailAddress findByUserId_First(long userId,
912                    OrderByComparator orderByComparator)
913                    throws NoSuchEmailAddressException, SystemException {
914                    List<EmailAddress> list = findByUserId(userId, 0, 1, orderByComparator);
915    
916                    if (list.isEmpty()) {
917                            StringBundler msg = new StringBundler(4);
918    
919                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
920    
921                            msg.append("userId=");
922                            msg.append(userId);
923    
924                            msg.append(StringPool.CLOSE_CURLY_BRACE);
925    
926                            throw new NoSuchEmailAddressException(msg.toString());
927                    }
928                    else {
929                            return list.get(0);
930                    }
931            }
932    
933            /**
934             * Finds the last email address in the ordered set where userId = &#63;.
935             *
936             * <p>
937             * 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.
938             * </p>
939             *
940             * @param userId the user id to search with
941             * @param orderByComparator the comparator to order the set by
942             * @return the last matching email address
943             * @throws com.liferay.portal.NoSuchEmailAddressException if a matching email address could not be found
944             * @throws SystemException if a system exception occurred
945             */
946            public EmailAddress findByUserId_Last(long userId,
947                    OrderByComparator orderByComparator)
948                    throws NoSuchEmailAddressException, SystemException {
949                    int count = countByUserId(userId);
950    
951                    List<EmailAddress> list = findByUserId(userId, count - 1, count,
952                                    orderByComparator);
953    
954                    if (list.isEmpty()) {
955                            StringBundler msg = new StringBundler(4);
956    
957                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
958    
959                            msg.append("userId=");
960                            msg.append(userId);
961    
962                            msg.append(StringPool.CLOSE_CURLY_BRACE);
963    
964                            throw new NoSuchEmailAddressException(msg.toString());
965                    }
966                    else {
967                            return list.get(0);
968                    }
969            }
970    
971            /**
972             * Finds the email addresses before and after the current email address in the ordered set where userId = &#63;.
973             *
974             * <p>
975             * 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.
976             * </p>
977             *
978             * @param emailAddressId the primary key of the current email address
979             * @param userId the user id to search with
980             * @param orderByComparator the comparator to order the set by
981             * @return the previous, current, and next email address
982             * @throws com.liferay.portal.NoSuchEmailAddressException if a email address with the primary key could not be found
983             * @throws SystemException if a system exception occurred
984             */
985            public EmailAddress[] findByUserId_PrevAndNext(long emailAddressId,
986                    long userId, OrderByComparator orderByComparator)
987                    throws NoSuchEmailAddressException, SystemException {
988                    EmailAddress emailAddress = findByPrimaryKey(emailAddressId);
989    
990                    Session session = null;
991    
992                    try {
993                            session = openSession();
994    
995                            EmailAddress[] array = new EmailAddressImpl[3];
996    
997                            array[0] = getByUserId_PrevAndNext(session, emailAddress, userId,
998                                            orderByComparator, true);
999    
1000                            array[1] = emailAddress;
1001    
1002                            array[2] = getByUserId_PrevAndNext(session, emailAddress, userId,
1003                                            orderByComparator, false);
1004    
1005                            return array;
1006                    }
1007                    catch (Exception e) {
1008                            throw processException(e);
1009                    }
1010                    finally {
1011                            closeSession(session);
1012                    }
1013            }
1014    
1015            protected EmailAddress getByUserId_PrevAndNext(Session session,
1016                    EmailAddress emailAddress, long userId,
1017                    OrderByComparator orderByComparator, boolean previous) {
1018                    StringBundler query = null;
1019    
1020                    if (orderByComparator != null) {
1021                            query = new StringBundler(6 +
1022                                            (orderByComparator.getOrderByFields().length * 6));
1023                    }
1024                    else {
1025                            query = new StringBundler(3);
1026                    }
1027    
1028                    query.append(_SQL_SELECT_EMAILADDRESS_WHERE);
1029    
1030                    query.append(_FINDER_COLUMN_USERID_USERID_2);
1031    
1032                    if (orderByComparator != null) {
1033                            String[] orderByFields = orderByComparator.getOrderByFields();
1034    
1035                            if (orderByFields.length > 0) {
1036                                    query.append(WHERE_AND);
1037                            }
1038    
1039                            for (int i = 0; i < orderByFields.length; i++) {
1040                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1041                                    query.append(orderByFields[i]);
1042    
1043                                    if ((i + 1) < orderByFields.length) {
1044                                            if (orderByComparator.isAscending() ^ previous) {
1045                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1046                                            }
1047                                            else {
1048                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1049                                            }
1050                                    }
1051                                    else {
1052                                            if (orderByComparator.isAscending() ^ previous) {
1053                                                    query.append(WHERE_GREATER_THAN);
1054                                            }
1055                                            else {
1056                                                    query.append(WHERE_LESSER_THAN);
1057                                            }
1058                                    }
1059                            }
1060    
1061                            query.append(ORDER_BY_CLAUSE);
1062    
1063                            for (int i = 0; i < orderByFields.length; i++) {
1064                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1065                                    query.append(orderByFields[i]);
1066    
1067                                    if ((i + 1) < orderByFields.length) {
1068                                            if (orderByComparator.isAscending() ^ previous) {
1069                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1070                                            }
1071                                            else {
1072                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1073                                            }
1074                                    }
1075                                    else {
1076                                            if (orderByComparator.isAscending() ^ previous) {
1077                                                    query.append(ORDER_BY_ASC);
1078                                            }
1079                                            else {
1080                                                    query.append(ORDER_BY_DESC);
1081                                            }
1082                                    }
1083                            }
1084                    }
1085    
1086                    else {
1087                            query.append(EmailAddressModelImpl.ORDER_BY_JPQL);
1088                    }
1089    
1090                    String sql = query.toString();
1091    
1092                    Query q = session.createQuery(sql);
1093    
1094                    q.setFirstResult(0);
1095                    q.setMaxResults(2);
1096    
1097                    QueryPos qPos = QueryPos.getInstance(q);
1098    
1099                    qPos.add(userId);
1100    
1101                    if (orderByComparator != null) {
1102                            Object[] values = orderByComparator.getOrderByValues(emailAddress);
1103    
1104                            for (Object value : values) {
1105                                    qPos.add(value);
1106                            }
1107                    }
1108    
1109                    List<EmailAddress> list = q.list();
1110    
1111                    if (list.size() == 2) {
1112                            return list.get(1);
1113                    }
1114                    else {
1115                            return null;
1116                    }
1117            }
1118    
1119            /**
1120             * Finds all the email addresses where companyId = &#63; and classNameId = &#63;.
1121             *
1122             * @param companyId the company id to search with
1123             * @param classNameId the class name id to search with
1124             * @return the matching email addresses
1125             * @throws SystemException if a system exception occurred
1126             */
1127            public List<EmailAddress> findByC_C(long companyId, long classNameId)
1128                    throws SystemException {
1129                    return findByC_C(companyId, classNameId, QueryUtil.ALL_POS,
1130                            QueryUtil.ALL_POS, null);
1131            }
1132    
1133            /**
1134             * Finds a range of all the email addresses where companyId = &#63; and classNameId = &#63;.
1135             *
1136             * <p>
1137             * 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.
1138             * </p>
1139             *
1140             * @param companyId the company id to search with
1141             * @param classNameId the class name id to search with
1142             * @param start the lower bound of the range of email addresses to return
1143             * @param end the upper bound of the range of email addresses to return (not inclusive)
1144             * @return the range of matching email addresses
1145             * @throws SystemException if a system exception occurred
1146             */
1147            public List<EmailAddress> findByC_C(long companyId, long classNameId,
1148                    int start, int end) throws SystemException {
1149                    return findByC_C(companyId, classNameId, start, end, null);
1150            }
1151    
1152            /**
1153             * Finds an ordered range of all the email addresses where companyId = &#63; and classNameId = &#63;.
1154             *
1155             * <p>
1156             * 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.
1157             * </p>
1158             *
1159             * @param companyId the company id to search with
1160             * @param classNameId the class name id to search with
1161             * @param start the lower bound of the range of email addresses to return
1162             * @param end the upper bound of the range of email addresses to return (not inclusive)
1163             * @param orderByComparator the comparator to order the results by
1164             * @return the ordered range of matching email addresses
1165             * @throws SystemException if a system exception occurred
1166             */
1167            public List<EmailAddress> findByC_C(long companyId, long classNameId,
1168                    int start, int end, OrderByComparator orderByComparator)
1169                    throws SystemException {
1170                    Object[] finderArgs = new Object[] {
1171                                    companyId, classNameId,
1172                                    
1173                                    String.valueOf(start), String.valueOf(end),
1174                                    String.valueOf(orderByComparator)
1175                            };
1176    
1177                    List<EmailAddress> list = (List<EmailAddress>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_C,
1178                                    finderArgs, this);
1179    
1180                    if (list == null) {
1181                            Session session = null;
1182    
1183                            try {
1184                                    session = openSession();
1185    
1186                                    StringBundler query = null;
1187    
1188                                    if (orderByComparator != null) {
1189                                            query = new StringBundler(4 +
1190                                                            (orderByComparator.getOrderByFields().length * 3));
1191                                    }
1192                                    else {
1193                                            query = new StringBundler(4);
1194                                    }
1195    
1196                                    query.append(_SQL_SELECT_EMAILADDRESS_WHERE);
1197    
1198                                    query.append(_FINDER_COLUMN_C_C_COMPANYID_2);
1199    
1200                                    query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
1201    
1202                                    if (orderByComparator != null) {
1203                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1204                                                    orderByComparator);
1205                                    }
1206    
1207                                    else {
1208                                            query.append(EmailAddressModelImpl.ORDER_BY_JPQL);
1209                                    }
1210    
1211                                    String sql = query.toString();
1212    
1213                                    Query q = session.createQuery(sql);
1214    
1215                                    QueryPos qPos = QueryPos.getInstance(q);
1216    
1217                                    qPos.add(companyId);
1218    
1219                                    qPos.add(classNameId);
1220    
1221                                    list = (List<EmailAddress>)QueryUtil.list(q, getDialect(),
1222                                                    start, end);
1223                            }
1224                            catch (Exception e) {
1225                                    throw processException(e);
1226                            }
1227                            finally {
1228                                    if (list == null) {
1229                                            list = new ArrayList<EmailAddress>();
1230                                    }
1231    
1232                                    cacheResult(list);
1233    
1234                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_C, finderArgs,
1235                                            list);
1236    
1237                                    closeSession(session);
1238                            }
1239                    }
1240    
1241                    return list;
1242            }
1243    
1244            /**
1245             * Finds the first email address in the ordered set where companyId = &#63; and classNameId = &#63;.
1246             *
1247             * <p>
1248             * 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.
1249             * </p>
1250             *
1251             * @param companyId the company id to search with
1252             * @param classNameId the class name id to search with
1253             * @param orderByComparator the comparator to order the set by
1254             * @return the first matching email address
1255             * @throws com.liferay.portal.NoSuchEmailAddressException if a matching email address could not be found
1256             * @throws SystemException if a system exception occurred
1257             */
1258            public EmailAddress findByC_C_First(long companyId, long classNameId,
1259                    OrderByComparator orderByComparator)
1260                    throws NoSuchEmailAddressException, SystemException {
1261                    List<EmailAddress> list = findByC_C(companyId, classNameId, 0, 1,
1262                                    orderByComparator);
1263    
1264                    if (list.isEmpty()) {
1265                            StringBundler msg = new StringBundler(6);
1266    
1267                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1268    
1269                            msg.append("companyId=");
1270                            msg.append(companyId);
1271    
1272                            msg.append(", classNameId=");
1273                            msg.append(classNameId);
1274    
1275                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1276    
1277                            throw new NoSuchEmailAddressException(msg.toString());
1278                    }
1279                    else {
1280                            return list.get(0);
1281                    }
1282            }
1283    
1284            /**
1285             * Finds the last email address in the ordered set where companyId = &#63; and classNameId = &#63;.
1286             *
1287             * <p>
1288             * 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.
1289             * </p>
1290             *
1291             * @param companyId the company id to search with
1292             * @param classNameId the class name id to search with
1293             * @param orderByComparator the comparator to order the set by
1294             * @return the last matching email address
1295             * @throws com.liferay.portal.NoSuchEmailAddressException if a matching email address could not be found
1296             * @throws SystemException if a system exception occurred
1297             */
1298            public EmailAddress findByC_C_Last(long companyId, long classNameId,
1299                    OrderByComparator orderByComparator)
1300                    throws NoSuchEmailAddressException, SystemException {
1301                    int count = countByC_C(companyId, classNameId);
1302    
1303                    List<EmailAddress> list = findByC_C(companyId, classNameId, count - 1,
1304                                    count, orderByComparator);
1305    
1306                    if (list.isEmpty()) {
1307                            StringBundler msg = new StringBundler(6);
1308    
1309                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1310    
1311                            msg.append("companyId=");
1312                            msg.append(companyId);
1313    
1314                            msg.append(", classNameId=");
1315                            msg.append(classNameId);
1316    
1317                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1318    
1319                            throw new NoSuchEmailAddressException(msg.toString());
1320                    }
1321                    else {
1322                            return list.get(0);
1323                    }
1324            }
1325    
1326            /**
1327             * Finds the email addresses before and after the current email address in the ordered set where companyId = &#63; and classNameId = &#63;.
1328             *
1329             * <p>
1330             * 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.
1331             * </p>
1332             *
1333             * @param emailAddressId the primary key of the current email address
1334             * @param companyId the company id to search with
1335             * @param classNameId the class name id to search with
1336             * @param orderByComparator the comparator to order the set by
1337             * @return the previous, current, and next email address
1338             * @throws com.liferay.portal.NoSuchEmailAddressException if a email address with the primary key could not be found
1339             * @throws SystemException if a system exception occurred
1340             */
1341            public EmailAddress[] findByC_C_PrevAndNext(long emailAddressId,
1342                    long companyId, long classNameId, OrderByComparator orderByComparator)
1343                    throws NoSuchEmailAddressException, SystemException {
1344                    EmailAddress emailAddress = findByPrimaryKey(emailAddressId);
1345    
1346                    Session session = null;
1347    
1348                    try {
1349                            session = openSession();
1350    
1351                            EmailAddress[] array = new EmailAddressImpl[3];
1352    
1353                            array[0] = getByC_C_PrevAndNext(session, emailAddress, companyId,
1354                                            classNameId, orderByComparator, true);
1355    
1356                            array[1] = emailAddress;
1357    
1358                            array[2] = getByC_C_PrevAndNext(session, emailAddress, companyId,
1359                                            classNameId, orderByComparator, false);
1360    
1361                            return array;
1362                    }
1363                    catch (Exception e) {
1364                            throw processException(e);
1365                    }
1366                    finally {
1367                            closeSession(session);
1368                    }
1369            }
1370    
1371            protected EmailAddress getByC_C_PrevAndNext(Session session,
1372                    EmailAddress emailAddress, long companyId, long classNameId,
1373                    OrderByComparator orderByComparator, boolean previous) {
1374                    StringBundler query = null;
1375    
1376                    if (orderByComparator != null) {
1377                            query = new StringBundler(6 +
1378                                            (orderByComparator.getOrderByFields().length * 6));
1379                    }
1380                    else {
1381                            query = new StringBundler(3);
1382                    }
1383    
1384                    query.append(_SQL_SELECT_EMAILADDRESS_WHERE);
1385    
1386                    query.append(_FINDER_COLUMN_C_C_COMPANYID_2);
1387    
1388                    query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
1389    
1390                    if (orderByComparator != null) {
1391                            String[] orderByFields = orderByComparator.getOrderByFields();
1392    
1393                            if (orderByFields.length > 0) {
1394                                    query.append(WHERE_AND);
1395                            }
1396    
1397                            for (int i = 0; i < orderByFields.length; i++) {
1398                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1399                                    query.append(orderByFields[i]);
1400    
1401                                    if ((i + 1) < orderByFields.length) {
1402                                            if (orderByComparator.isAscending() ^ previous) {
1403                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1404                                            }
1405                                            else {
1406                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1407                                            }
1408                                    }
1409                                    else {
1410                                            if (orderByComparator.isAscending() ^ previous) {
1411                                                    query.append(WHERE_GREATER_THAN);
1412                                            }
1413                                            else {
1414                                                    query.append(WHERE_LESSER_THAN);
1415                                            }
1416                                    }
1417                            }
1418    
1419                            query.append(ORDER_BY_CLAUSE);
1420    
1421                            for (int i = 0; i < orderByFields.length; i++) {
1422                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1423                                    query.append(orderByFields[i]);
1424    
1425                                    if ((i + 1) < orderByFields.length) {
1426                                            if (orderByComparator.isAscending() ^ previous) {
1427                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1428                                            }
1429                                            else {
1430                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1431                                            }
1432                                    }
1433                                    else {
1434                                            if (orderByComparator.isAscending() ^ previous) {
1435                                                    query.append(ORDER_BY_ASC);
1436                                            }
1437                                            else {
1438                                                    query.append(ORDER_BY_DESC);
1439                                            }
1440                                    }
1441                            }
1442                    }
1443    
1444                    else {
1445                            query.append(EmailAddressModelImpl.ORDER_BY_JPQL);
1446                    }
1447    
1448                    String sql = query.toString();
1449    
1450                    Query q = session.createQuery(sql);
1451    
1452                    q.setFirstResult(0);
1453                    q.setMaxResults(2);
1454    
1455                    QueryPos qPos = QueryPos.getInstance(q);
1456    
1457                    qPos.add(companyId);
1458    
1459                    qPos.add(classNameId);
1460    
1461                    if (orderByComparator != null) {
1462                            Object[] values = orderByComparator.getOrderByValues(emailAddress);
1463    
1464                            for (Object value : values) {
1465                                    qPos.add(value);
1466                            }
1467                    }
1468    
1469                    List<EmailAddress> list = q.list();
1470    
1471                    if (list.size() == 2) {
1472                            return list.get(1);
1473                    }
1474                    else {
1475                            return null;
1476                    }
1477            }
1478    
1479            /**
1480             * Finds all the email addresses where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
1481             *
1482             * @param companyId the company id to search with
1483             * @param classNameId the class name id to search with
1484             * @param classPK the class p k to search with
1485             * @return the matching email addresses
1486             * @throws SystemException if a system exception occurred
1487             */
1488            public List<EmailAddress> findByC_C_C(long companyId, long classNameId,
1489                    long classPK) throws SystemException {
1490                    return findByC_C_C(companyId, classNameId, classPK, QueryUtil.ALL_POS,
1491                            QueryUtil.ALL_POS, null);
1492            }
1493    
1494            /**
1495             * Finds a range of all the email addresses where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
1496             *
1497             * <p>
1498             * 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.
1499             * </p>
1500             *
1501             * @param companyId the company id to search with
1502             * @param classNameId the class name id to search with
1503             * @param classPK the class p k to search with
1504             * @param start the lower bound of the range of email addresses to return
1505             * @param end the upper bound of the range of email addresses to return (not inclusive)
1506             * @return the range of matching email addresses
1507             * @throws SystemException if a system exception occurred
1508             */
1509            public List<EmailAddress> findByC_C_C(long companyId, long classNameId,
1510                    long classPK, int start, int end) throws SystemException {
1511                    return findByC_C_C(companyId, classNameId, classPK, start, end, null);
1512            }
1513    
1514            /**
1515             * Finds an ordered range of all the email addresses where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
1516             *
1517             * <p>
1518             * 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.
1519             * </p>
1520             *
1521             * @param companyId the company id to search with
1522             * @param classNameId the class name id to search with
1523             * @param classPK the class p k to search with
1524             * @param start the lower bound of the range of email addresses to return
1525             * @param end the upper bound of the range of email addresses to return (not inclusive)
1526             * @param orderByComparator the comparator to order the results by
1527             * @return the ordered range of matching email addresses
1528             * @throws SystemException if a system exception occurred
1529             */
1530            public List<EmailAddress> findByC_C_C(long companyId, long classNameId,
1531                    long classPK, int start, int end, OrderByComparator orderByComparator)
1532                    throws SystemException {
1533                    Object[] finderArgs = new Object[] {
1534                                    companyId, classNameId, classPK,
1535                                    
1536                                    String.valueOf(start), String.valueOf(end),
1537                                    String.valueOf(orderByComparator)
1538                            };
1539    
1540                    List<EmailAddress> list = (List<EmailAddress>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_C_C,
1541                                    finderArgs, this);
1542    
1543                    if (list == null) {
1544                            Session session = null;
1545    
1546                            try {
1547                                    session = openSession();
1548    
1549                                    StringBundler query = null;
1550    
1551                                    if (orderByComparator != null) {
1552                                            query = new StringBundler(5 +
1553                                                            (orderByComparator.getOrderByFields().length * 3));
1554                                    }
1555                                    else {
1556                                            query = new StringBundler(5);
1557                                    }
1558    
1559                                    query.append(_SQL_SELECT_EMAILADDRESS_WHERE);
1560    
1561                                    query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
1562    
1563                                    query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
1564    
1565                                    query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
1566    
1567                                    if (orderByComparator != null) {
1568                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1569                                                    orderByComparator);
1570                                    }
1571    
1572                                    else {
1573                                            query.append(EmailAddressModelImpl.ORDER_BY_JPQL);
1574                                    }
1575    
1576                                    String sql = query.toString();
1577    
1578                                    Query q = session.createQuery(sql);
1579    
1580                                    QueryPos qPos = QueryPos.getInstance(q);
1581    
1582                                    qPos.add(companyId);
1583    
1584                                    qPos.add(classNameId);
1585    
1586                                    qPos.add(classPK);
1587    
1588                                    list = (List<EmailAddress>)QueryUtil.list(q, getDialect(),
1589                                                    start, end);
1590                            }
1591                            catch (Exception e) {
1592                                    throw processException(e);
1593                            }
1594                            finally {
1595                                    if (list == null) {
1596                                            list = new ArrayList<EmailAddress>();
1597                                    }
1598    
1599                                    cacheResult(list);
1600    
1601                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_C_C,
1602                                            finderArgs, list);
1603    
1604                                    closeSession(session);
1605                            }
1606                    }
1607    
1608                    return list;
1609            }
1610    
1611            /**
1612             * Finds the first email address in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
1613             *
1614             * <p>
1615             * 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.
1616             * </p>
1617             *
1618             * @param companyId the company id to search with
1619             * @param classNameId the class name id to search with
1620             * @param classPK the class p k to search with
1621             * @param orderByComparator the comparator to order the set by
1622             * @return the first matching email address
1623             * @throws com.liferay.portal.NoSuchEmailAddressException if a matching email address could not be found
1624             * @throws SystemException if a system exception occurred
1625             */
1626            public EmailAddress findByC_C_C_First(long companyId, long classNameId,
1627                    long classPK, OrderByComparator orderByComparator)
1628                    throws NoSuchEmailAddressException, SystemException {
1629                    List<EmailAddress> list = findByC_C_C(companyId, classNameId, classPK,
1630                                    0, 1, orderByComparator);
1631    
1632                    if (list.isEmpty()) {
1633                            StringBundler msg = new StringBundler(8);
1634    
1635                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1636    
1637                            msg.append("companyId=");
1638                            msg.append(companyId);
1639    
1640                            msg.append(", classNameId=");
1641                            msg.append(classNameId);
1642    
1643                            msg.append(", classPK=");
1644                            msg.append(classPK);
1645    
1646                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1647    
1648                            throw new NoSuchEmailAddressException(msg.toString());
1649                    }
1650                    else {
1651                            return list.get(0);
1652                    }
1653            }
1654    
1655            /**
1656             * Finds the last email address in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
1657             *
1658             * <p>
1659             * 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.
1660             * </p>
1661             *
1662             * @param companyId the company id to search with
1663             * @param classNameId the class name id to search with
1664             * @param classPK the class p k to search with
1665             * @param orderByComparator the comparator to order the set by
1666             * @return the last matching email address
1667             * @throws com.liferay.portal.NoSuchEmailAddressException if a matching email address could not be found
1668             * @throws SystemException if a system exception occurred
1669             */
1670            public EmailAddress findByC_C_C_Last(long companyId, long classNameId,
1671                    long classPK, OrderByComparator orderByComparator)
1672                    throws NoSuchEmailAddressException, SystemException {
1673                    int count = countByC_C_C(companyId, classNameId, classPK);
1674    
1675                    List<EmailAddress> list = findByC_C_C(companyId, classNameId, classPK,
1676                                    count - 1, count, orderByComparator);
1677    
1678                    if (list.isEmpty()) {
1679                            StringBundler msg = new StringBundler(8);
1680    
1681                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1682    
1683                            msg.append("companyId=");
1684                            msg.append(companyId);
1685    
1686                            msg.append(", classNameId=");
1687                            msg.append(classNameId);
1688    
1689                            msg.append(", classPK=");
1690                            msg.append(classPK);
1691    
1692                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1693    
1694                            throw new NoSuchEmailAddressException(msg.toString());
1695                    }
1696                    else {
1697                            return list.get(0);
1698                    }
1699            }
1700    
1701            /**
1702             * Finds the email addresses before and after the current email address in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
1703             *
1704             * <p>
1705             * 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.
1706             * </p>
1707             *
1708             * @param emailAddressId the primary key of the current email address
1709             * @param companyId the company id to search with
1710             * @param classNameId the class name id to search with
1711             * @param classPK the class p k to search with
1712             * @param orderByComparator the comparator to order the set by
1713             * @return the previous, current, and next email address
1714             * @throws com.liferay.portal.NoSuchEmailAddressException if a email address with the primary key could not be found
1715             * @throws SystemException if a system exception occurred
1716             */
1717            public EmailAddress[] findByC_C_C_PrevAndNext(long emailAddressId,
1718                    long companyId, long classNameId, long classPK,
1719                    OrderByComparator orderByComparator)
1720                    throws NoSuchEmailAddressException, SystemException {
1721                    EmailAddress emailAddress = findByPrimaryKey(emailAddressId);
1722    
1723                    Session session = null;
1724    
1725                    try {
1726                            session = openSession();
1727    
1728                            EmailAddress[] array = new EmailAddressImpl[3];
1729    
1730                            array[0] = getByC_C_C_PrevAndNext(session, emailAddress, companyId,
1731                                            classNameId, classPK, orderByComparator, true);
1732    
1733                            array[1] = emailAddress;
1734    
1735                            array[2] = getByC_C_C_PrevAndNext(session, emailAddress, companyId,
1736                                            classNameId, classPK, orderByComparator, false);
1737    
1738                            return array;
1739                    }
1740                    catch (Exception e) {
1741                            throw processException(e);
1742                    }
1743                    finally {
1744                            closeSession(session);
1745                    }
1746            }
1747    
1748            protected EmailAddress getByC_C_C_PrevAndNext(Session session,
1749                    EmailAddress emailAddress, long companyId, long classNameId,
1750                    long classPK, OrderByComparator orderByComparator, boolean previous) {
1751                    StringBundler query = null;
1752    
1753                    if (orderByComparator != null) {
1754                            query = new StringBundler(6 +
1755                                            (orderByComparator.getOrderByFields().length * 6));
1756                    }
1757                    else {
1758                            query = new StringBundler(3);
1759                    }
1760    
1761                    query.append(_SQL_SELECT_EMAILADDRESS_WHERE);
1762    
1763                    query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
1764    
1765                    query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
1766    
1767                    query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
1768    
1769                    if (orderByComparator != null) {
1770                            String[] orderByFields = orderByComparator.getOrderByFields();
1771    
1772                            if (orderByFields.length > 0) {
1773                                    query.append(WHERE_AND);
1774                            }
1775    
1776                            for (int i = 0; i < orderByFields.length; i++) {
1777                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1778                                    query.append(orderByFields[i]);
1779    
1780                                    if ((i + 1) < orderByFields.length) {
1781                                            if (orderByComparator.isAscending() ^ previous) {
1782                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1783                                            }
1784                                            else {
1785                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1786                                            }
1787                                    }
1788                                    else {
1789                                            if (orderByComparator.isAscending() ^ previous) {
1790                                                    query.append(WHERE_GREATER_THAN);
1791                                            }
1792                                            else {
1793                                                    query.append(WHERE_LESSER_THAN);
1794                                            }
1795                                    }
1796                            }
1797    
1798                            query.append(ORDER_BY_CLAUSE);
1799    
1800                            for (int i = 0; i < orderByFields.length; i++) {
1801                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1802                                    query.append(orderByFields[i]);
1803    
1804                                    if ((i + 1) < orderByFields.length) {
1805                                            if (orderByComparator.isAscending() ^ previous) {
1806                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1807                                            }
1808                                            else {
1809                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1810                                            }
1811                                    }
1812                                    else {
1813                                            if (orderByComparator.isAscending() ^ previous) {
1814                                                    query.append(ORDER_BY_ASC);
1815                                            }
1816                                            else {
1817                                                    query.append(ORDER_BY_DESC);
1818                                            }
1819                                    }
1820                            }
1821                    }
1822    
1823                    else {
1824                            query.append(EmailAddressModelImpl.ORDER_BY_JPQL);
1825                    }
1826    
1827                    String sql = query.toString();
1828    
1829                    Query q = session.createQuery(sql);
1830    
1831                    q.setFirstResult(0);
1832                    q.setMaxResults(2);
1833    
1834                    QueryPos qPos = QueryPos.getInstance(q);
1835    
1836                    qPos.add(companyId);
1837    
1838                    qPos.add(classNameId);
1839    
1840                    qPos.add(classPK);
1841    
1842                    if (orderByComparator != null) {
1843                            Object[] values = orderByComparator.getOrderByValues(emailAddress);
1844    
1845                            for (Object value : values) {
1846                                    qPos.add(value);
1847                            }
1848                    }
1849    
1850                    List<EmailAddress> list = q.list();
1851    
1852                    if (list.size() == 2) {
1853                            return list.get(1);
1854                    }
1855                    else {
1856                            return null;
1857                    }
1858            }
1859    
1860            /**
1861             * Finds all the email addresses where companyId = &#63; and classNameId = &#63; and classPK = &#63; and primary = &#63;.
1862             *
1863             * @param companyId the company id to search with
1864             * @param classNameId the class name id to search with
1865             * @param classPK the class p k to search with
1866             * @param primary the primary to search with
1867             * @return the matching email addresses
1868             * @throws SystemException if a system exception occurred
1869             */
1870            public List<EmailAddress> findByC_C_C_P(long companyId, long classNameId,
1871                    long classPK, boolean primary) throws SystemException {
1872                    return findByC_C_C_P(companyId, classNameId, classPK, primary,
1873                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1874            }
1875    
1876            /**
1877             * Finds a range of all the email addresses where companyId = &#63; and classNameId = &#63; and classPK = &#63; and primary = &#63;.
1878             *
1879             * <p>
1880             * 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.
1881             * </p>
1882             *
1883             * @param companyId the company id to search with
1884             * @param classNameId the class name id to search with
1885             * @param classPK the class p k to search with
1886             * @param primary the primary to search with
1887             * @param start the lower bound of the range of email addresses to return
1888             * @param end the upper bound of the range of email addresses to return (not inclusive)
1889             * @return the range of matching email addresses
1890             * @throws SystemException if a system exception occurred
1891             */
1892            public List<EmailAddress> findByC_C_C_P(long companyId, long classNameId,
1893                    long classPK, boolean primary, int start, int end)
1894                    throws SystemException {
1895                    return findByC_C_C_P(companyId, classNameId, classPK, primary, start,
1896                            end, null);
1897            }
1898    
1899            /**
1900             * Finds an ordered range of all the email addresses where companyId = &#63; and classNameId = &#63; and classPK = &#63; and primary = &#63;.
1901             *
1902             * <p>
1903             * 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.
1904             * </p>
1905             *
1906             * @param companyId the company id to search with
1907             * @param classNameId the class name id to search with
1908             * @param classPK the class p k to search with
1909             * @param primary the primary to search with
1910             * @param start the lower bound of the range of email addresses to return
1911             * @param end the upper bound of the range of email addresses to return (not inclusive)
1912             * @param orderByComparator the comparator to order the results by
1913             * @return the ordered range of matching email addresses
1914             * @throws SystemException if a system exception occurred
1915             */
1916            public List<EmailAddress> findByC_C_C_P(long companyId, long classNameId,
1917                    long classPK, boolean primary, int start, int end,
1918                    OrderByComparator orderByComparator) throws SystemException {
1919                    Object[] finderArgs = new Object[] {
1920                                    companyId, classNameId, classPK, primary,
1921                                    
1922                                    String.valueOf(start), String.valueOf(end),
1923                                    String.valueOf(orderByComparator)
1924                            };
1925    
1926                    List<EmailAddress> list = (List<EmailAddress>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_C_C_P,
1927                                    finderArgs, this);
1928    
1929                    if (list == null) {
1930                            Session session = null;
1931    
1932                            try {
1933                                    session = openSession();
1934    
1935                                    StringBundler query = null;
1936    
1937                                    if (orderByComparator != null) {
1938                                            query = new StringBundler(6 +
1939                                                            (orderByComparator.getOrderByFields().length * 3));
1940                                    }
1941                                    else {
1942                                            query = new StringBundler(6);
1943                                    }
1944    
1945                                    query.append(_SQL_SELECT_EMAILADDRESS_WHERE);
1946    
1947                                    query.append(_FINDER_COLUMN_C_C_C_P_COMPANYID_2);
1948    
1949                                    query.append(_FINDER_COLUMN_C_C_C_P_CLASSNAMEID_2);
1950    
1951                                    query.append(_FINDER_COLUMN_C_C_C_P_CLASSPK_2);
1952    
1953                                    query.append(_FINDER_COLUMN_C_C_C_P_PRIMARY_2);
1954    
1955                                    if (orderByComparator != null) {
1956                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1957                                                    orderByComparator);
1958                                    }
1959    
1960                                    else {
1961                                            query.append(EmailAddressModelImpl.ORDER_BY_JPQL);
1962                                    }
1963    
1964                                    String sql = query.toString();
1965    
1966                                    Query q = session.createQuery(sql);
1967    
1968                                    QueryPos qPos = QueryPos.getInstance(q);
1969    
1970                                    qPos.add(companyId);
1971    
1972                                    qPos.add(classNameId);
1973    
1974                                    qPos.add(classPK);
1975    
1976                                    qPos.add(primary);
1977    
1978                                    list = (List<EmailAddress>)QueryUtil.list(q, getDialect(),
1979                                                    start, end);
1980                            }
1981                            catch (Exception e) {
1982                                    throw processException(e);
1983                            }
1984                            finally {
1985                                    if (list == null) {
1986                                            list = new ArrayList<EmailAddress>();
1987                                    }
1988    
1989                                    cacheResult(list);
1990    
1991                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_C_C_P,
1992                                            finderArgs, list);
1993    
1994                                    closeSession(session);
1995                            }
1996                    }
1997    
1998                    return list;
1999            }
2000    
2001            /**
2002             * Finds the first email address in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63; and primary = &#63;.
2003             *
2004             * <p>
2005             * 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.
2006             * </p>
2007             *
2008             * @param companyId the company id to search with
2009             * @param classNameId the class name id to search with
2010             * @param classPK the class p k to search with
2011             * @param primary the primary to search with
2012             * @param orderByComparator the comparator to order the set by
2013             * @return the first matching email address
2014             * @throws com.liferay.portal.NoSuchEmailAddressException if a matching email address could not be found
2015             * @throws SystemException if a system exception occurred
2016             */
2017            public EmailAddress findByC_C_C_P_First(long companyId, long classNameId,
2018                    long classPK, boolean primary, OrderByComparator orderByComparator)
2019                    throws NoSuchEmailAddressException, SystemException {
2020                    List<EmailAddress> list = findByC_C_C_P(companyId, classNameId,
2021                                    classPK, primary, 0, 1, orderByComparator);
2022    
2023                    if (list.isEmpty()) {
2024                            StringBundler msg = new StringBundler(10);
2025    
2026                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2027    
2028                            msg.append("companyId=");
2029                            msg.append(companyId);
2030    
2031                            msg.append(", classNameId=");
2032                            msg.append(classNameId);
2033    
2034                            msg.append(", classPK=");
2035                            msg.append(classPK);
2036    
2037                            msg.append(", primary=");
2038                            msg.append(primary);
2039    
2040                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2041    
2042                            throw new NoSuchEmailAddressException(msg.toString());
2043                    }
2044                    else {
2045                            return list.get(0);
2046                    }
2047            }
2048    
2049            /**
2050             * Finds the last email address in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63; and primary = &#63;.
2051             *
2052             * <p>
2053             * 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.
2054             * </p>
2055             *
2056             * @param companyId the company id to search with
2057             * @param classNameId the class name id to search with
2058             * @param classPK the class p k to search with
2059             * @param primary the primary to search with
2060             * @param orderByComparator the comparator to order the set by
2061             * @return the last matching email address
2062             * @throws com.liferay.portal.NoSuchEmailAddressException if a matching email address could not be found
2063             * @throws SystemException if a system exception occurred
2064             */
2065            public EmailAddress findByC_C_C_P_Last(long companyId, long classNameId,
2066                    long classPK, boolean primary, OrderByComparator orderByComparator)
2067                    throws NoSuchEmailAddressException, SystemException {
2068                    int count = countByC_C_C_P(companyId, classNameId, classPK, primary);
2069    
2070                    List<EmailAddress> list = findByC_C_C_P(companyId, classNameId,
2071                                    classPK, primary, count - 1, count, orderByComparator);
2072    
2073                    if (list.isEmpty()) {
2074                            StringBundler msg = new StringBundler(10);
2075    
2076                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2077    
2078                            msg.append("companyId=");
2079                            msg.append(companyId);
2080    
2081                            msg.append(", classNameId=");
2082                            msg.append(classNameId);
2083    
2084                            msg.append(", classPK=");
2085                            msg.append(classPK);
2086    
2087                            msg.append(", primary=");
2088                            msg.append(primary);
2089    
2090                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2091    
2092                            throw new NoSuchEmailAddressException(msg.toString());
2093                    }
2094                    else {
2095                            return list.get(0);
2096                    }
2097            }
2098    
2099            /**
2100             * Finds 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;.
2101             *
2102             * <p>
2103             * 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.
2104             * </p>
2105             *
2106             * @param emailAddressId the primary key of the current email address
2107             * @param companyId the company id to search with
2108             * @param classNameId the class name id to search with
2109             * @param classPK the class p k to search with
2110             * @param primary the primary to search with
2111             * @param orderByComparator the comparator to order the set by
2112             * @return the previous, current, and next email address
2113             * @throws com.liferay.portal.NoSuchEmailAddressException if a email address with the primary key could not be found
2114             * @throws SystemException if a system exception occurred
2115             */
2116            public EmailAddress[] findByC_C_C_P_PrevAndNext(long emailAddressId,
2117                    long companyId, long classNameId, long classPK, boolean primary,
2118                    OrderByComparator orderByComparator)
2119                    throws NoSuchEmailAddressException, SystemException {
2120                    EmailAddress emailAddress = findByPrimaryKey(emailAddressId);
2121    
2122                    Session session = null;
2123    
2124                    try {
2125                            session = openSession();
2126    
2127                            EmailAddress[] array = new EmailAddressImpl[3];
2128    
2129                            array[0] = getByC_C_C_P_PrevAndNext(session, emailAddress,
2130                                            companyId, classNameId, classPK, primary,
2131                                            orderByComparator, true);
2132    
2133                            array[1] = emailAddress;
2134    
2135                            array[2] = getByC_C_C_P_PrevAndNext(session, emailAddress,
2136                                            companyId, classNameId, classPK, primary,
2137                                            orderByComparator, false);
2138    
2139                            return array;
2140                    }
2141                    catch (Exception e) {
2142                            throw processException(e);
2143                    }
2144                    finally {
2145                            closeSession(session);
2146                    }
2147            }
2148    
2149            protected EmailAddress getByC_C_C_P_PrevAndNext(Session session,
2150                    EmailAddress emailAddress, long companyId, long classNameId,
2151                    long classPK, boolean primary, OrderByComparator orderByComparator,
2152                    boolean previous) {
2153                    StringBundler query = null;
2154    
2155                    if (orderByComparator != null) {
2156                            query = new StringBundler(6 +
2157                                            (orderByComparator.getOrderByFields().length * 6));
2158                    }
2159                    else {
2160                            query = new StringBundler(3);
2161                    }
2162    
2163                    query.append(_SQL_SELECT_EMAILADDRESS_WHERE);
2164    
2165                    query.append(_FINDER_COLUMN_C_C_C_P_COMPANYID_2);
2166    
2167                    query.append(_FINDER_COLUMN_C_C_C_P_CLASSNAMEID_2);
2168    
2169                    query.append(_FINDER_COLUMN_C_C_C_P_CLASSPK_2);
2170    
2171                    query.append(_FINDER_COLUMN_C_C_C_P_PRIMARY_2);
2172    
2173                    if (orderByComparator != null) {
2174                            String[] orderByFields = orderByComparator.getOrderByFields();
2175    
2176                            if (orderByFields.length > 0) {
2177                                    query.append(WHERE_AND);
2178                            }
2179    
2180                            for (int i = 0; i < orderByFields.length; i++) {
2181                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2182                                    query.append(orderByFields[i]);
2183    
2184                                    if ((i + 1) < orderByFields.length) {
2185                                            if (orderByComparator.isAscending() ^ previous) {
2186                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2187                                            }
2188                                            else {
2189                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2190                                            }
2191                                    }
2192                                    else {
2193                                            if (orderByComparator.isAscending() ^ previous) {
2194                                                    query.append(WHERE_GREATER_THAN);
2195                                            }
2196                                            else {
2197                                                    query.append(WHERE_LESSER_THAN);
2198                                            }
2199                                    }
2200                            }
2201    
2202                            query.append(ORDER_BY_CLAUSE);
2203    
2204                            for (int i = 0; i < orderByFields.length; i++) {
2205                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2206                                    query.append(orderByFields[i]);
2207    
2208                                    if ((i + 1) < orderByFields.length) {
2209                                            if (orderByComparator.isAscending() ^ previous) {
2210                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2211                                            }
2212                                            else {
2213                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2214                                            }
2215                                    }
2216                                    else {
2217                                            if (orderByComparator.isAscending() ^ previous) {
2218                                                    query.append(ORDER_BY_ASC);
2219                                            }
2220                                            else {
2221                                                    query.append(ORDER_BY_DESC);
2222                                            }
2223                                    }
2224                            }
2225                    }
2226    
2227                    else {
2228                            query.append(EmailAddressModelImpl.ORDER_BY_JPQL);
2229                    }
2230    
2231                    String sql = query.toString();
2232    
2233                    Query q = session.createQuery(sql);
2234    
2235                    q.setFirstResult(0);
2236                    q.setMaxResults(2);
2237    
2238                    QueryPos qPos = QueryPos.getInstance(q);
2239    
2240                    qPos.add(companyId);
2241    
2242                    qPos.add(classNameId);
2243    
2244                    qPos.add(classPK);
2245    
2246                    qPos.add(primary);
2247    
2248                    if (orderByComparator != null) {
2249                            Object[] values = orderByComparator.getOrderByValues(emailAddress);
2250    
2251                            for (Object value : values) {
2252                                    qPos.add(value);
2253                            }
2254                    }
2255    
2256                    List<EmailAddress> list = q.list();
2257    
2258                    if (list.size() == 2) {
2259                            return list.get(1);
2260                    }
2261                    else {
2262                            return null;
2263                    }
2264            }
2265    
2266            /**
2267             * Finds all the email addresses.
2268             *
2269             * @return the email addresses
2270             * @throws SystemException if a system exception occurred
2271             */
2272            public List<EmailAddress> findAll() throws SystemException {
2273                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2274            }
2275    
2276            /**
2277             * Finds a range of all the email addresses.
2278             *
2279             * <p>
2280             * 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.
2281             * </p>
2282             *
2283             * @param start the lower bound of the range of email addresses to return
2284             * @param end the upper bound of the range of email addresses to return (not inclusive)
2285             * @return the range of email addresses
2286             * @throws SystemException if a system exception occurred
2287             */
2288            public List<EmailAddress> findAll(int start, int end)
2289                    throws SystemException {
2290                    return findAll(start, end, null);
2291            }
2292    
2293            /**
2294             * Finds an ordered range of all the email addresses.
2295             *
2296             * <p>
2297             * 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.
2298             * </p>
2299             *
2300             * @param start the lower bound of the range of email addresses to return
2301             * @param end the upper bound of the range of email addresses to return (not inclusive)
2302             * @param orderByComparator the comparator to order the results by
2303             * @return the ordered range of email addresses
2304             * @throws SystemException if a system exception occurred
2305             */
2306            public List<EmailAddress> findAll(int start, int end,
2307                    OrderByComparator orderByComparator) throws SystemException {
2308                    Object[] finderArgs = new Object[] {
2309                                    String.valueOf(start), String.valueOf(end),
2310                                    String.valueOf(orderByComparator)
2311                            };
2312    
2313                    List<EmailAddress> list = (List<EmailAddress>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
2314                                    finderArgs, this);
2315    
2316                    if (list == null) {
2317                            Session session = null;
2318    
2319                            try {
2320                                    session = openSession();
2321    
2322                                    StringBundler query = null;
2323                                    String sql = null;
2324    
2325                                    if (orderByComparator != null) {
2326                                            query = new StringBundler(2 +
2327                                                            (orderByComparator.getOrderByFields().length * 3));
2328    
2329                                            query.append(_SQL_SELECT_EMAILADDRESS);
2330    
2331                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2332                                                    orderByComparator);
2333    
2334                                            sql = query.toString();
2335                                    }
2336                                    else {
2337                                            sql = _SQL_SELECT_EMAILADDRESS.concat(EmailAddressModelImpl.ORDER_BY_JPQL);
2338                                    }
2339    
2340                                    Query q = session.createQuery(sql);
2341    
2342                                    if (orderByComparator == null) {
2343                                            list = (List<EmailAddress>)QueryUtil.list(q, getDialect(),
2344                                                            start, end, false);
2345    
2346                                            Collections.sort(list);
2347                                    }
2348                                    else {
2349                                            list = (List<EmailAddress>)QueryUtil.list(q, getDialect(),
2350                                                            start, end);
2351                                    }
2352                            }
2353                            catch (Exception e) {
2354                                    throw processException(e);
2355                            }
2356                            finally {
2357                                    if (list == null) {
2358                                            list = new ArrayList<EmailAddress>();
2359                                    }
2360    
2361                                    cacheResult(list);
2362    
2363                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
2364    
2365                                    closeSession(session);
2366                            }
2367                    }
2368    
2369                    return list;
2370            }
2371    
2372            /**
2373             * Removes all the email addresses where companyId = &#63; from the database.
2374             *
2375             * @param companyId the company id to search with
2376             * @throws SystemException if a system exception occurred
2377             */
2378            public void removeByCompanyId(long companyId) throws SystemException {
2379                    for (EmailAddress emailAddress : findByCompanyId(companyId)) {
2380                            remove(emailAddress);
2381                    }
2382            }
2383    
2384            /**
2385             * Removes all the email addresses where userId = &#63; from the database.
2386             *
2387             * @param userId the user id to search with
2388             * @throws SystemException if a system exception occurred
2389             */
2390            public void removeByUserId(long userId) throws SystemException {
2391                    for (EmailAddress emailAddress : findByUserId(userId)) {
2392                            remove(emailAddress);
2393                    }
2394            }
2395    
2396            /**
2397             * Removes all the email addresses where companyId = &#63; and classNameId = &#63; from the database.
2398             *
2399             * @param companyId the company id to search with
2400             * @param classNameId the class name id to search with
2401             * @throws SystemException if a system exception occurred
2402             */
2403            public void removeByC_C(long companyId, long classNameId)
2404                    throws SystemException {
2405                    for (EmailAddress emailAddress : findByC_C(companyId, classNameId)) {
2406                            remove(emailAddress);
2407                    }
2408            }
2409    
2410            /**
2411             * Removes all the email addresses where companyId = &#63; and classNameId = &#63; and classPK = &#63; from the database.
2412             *
2413             * @param companyId the company id to search with
2414             * @param classNameId the class name id to search with
2415             * @param classPK the class p k to search with
2416             * @throws SystemException if a system exception occurred
2417             */
2418            public void removeByC_C_C(long companyId, long classNameId, long classPK)
2419                    throws SystemException {
2420                    for (EmailAddress emailAddress : findByC_C_C(companyId, classNameId,
2421                                    classPK)) {
2422                            remove(emailAddress);
2423                    }
2424            }
2425    
2426            /**
2427             * Removes all the email addresses where companyId = &#63; and classNameId = &#63; and classPK = &#63; and primary = &#63; from the database.
2428             *
2429             * @param companyId the company id to search with
2430             * @param classNameId the class name id to search with
2431             * @param classPK the class p k to search with
2432             * @param primary the primary to search with
2433             * @throws SystemException if a system exception occurred
2434             */
2435            public void removeByC_C_C_P(long companyId, long classNameId, long classPK,
2436                    boolean primary) throws SystemException {
2437                    for (EmailAddress emailAddress : findByC_C_C_P(companyId, classNameId,
2438                                    classPK, primary)) {
2439                            remove(emailAddress);
2440                    }
2441            }
2442    
2443            /**
2444             * Removes all the email addresses from the database.
2445             *
2446             * @throws SystemException if a system exception occurred
2447             */
2448            public void removeAll() throws SystemException {
2449                    for (EmailAddress emailAddress : findAll()) {
2450                            remove(emailAddress);
2451                    }
2452            }
2453    
2454            /**
2455             * Counts all the email addresses where companyId = &#63;.
2456             *
2457             * @param companyId the company id to search with
2458             * @return the number of matching email addresses
2459             * @throws SystemException if a system exception occurred
2460             */
2461            public int countByCompanyId(long companyId) throws SystemException {
2462                    Object[] finderArgs = new Object[] { companyId };
2463    
2464                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
2465                                    finderArgs, this);
2466    
2467                    if (count == null) {
2468                            Session session = null;
2469    
2470                            try {
2471                                    session = openSession();
2472    
2473                                    StringBundler query = new StringBundler(2);
2474    
2475                                    query.append(_SQL_COUNT_EMAILADDRESS_WHERE);
2476    
2477                                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2478    
2479                                    String sql = query.toString();
2480    
2481                                    Query q = session.createQuery(sql);
2482    
2483                                    QueryPos qPos = QueryPos.getInstance(q);
2484    
2485                                    qPos.add(companyId);
2486    
2487                                    count = (Long)q.uniqueResult();
2488                            }
2489                            catch (Exception e) {
2490                                    throw processException(e);
2491                            }
2492                            finally {
2493                                    if (count == null) {
2494                                            count = Long.valueOf(0);
2495                                    }
2496    
2497                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
2498                                            finderArgs, count);
2499    
2500                                    closeSession(session);
2501                            }
2502                    }
2503    
2504                    return count.intValue();
2505            }
2506    
2507            /**
2508             * Counts all the email addresses where userId = &#63;.
2509             *
2510             * @param userId the user id to search with
2511             * @return the number of matching email addresses
2512             * @throws SystemException if a system exception occurred
2513             */
2514            public int countByUserId(long userId) throws SystemException {
2515                    Object[] finderArgs = new Object[] { userId };
2516    
2517                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
2518                                    finderArgs, this);
2519    
2520                    if (count == null) {
2521                            Session session = null;
2522    
2523                            try {
2524                                    session = openSession();
2525    
2526                                    StringBundler query = new StringBundler(2);
2527    
2528                                    query.append(_SQL_COUNT_EMAILADDRESS_WHERE);
2529    
2530                                    query.append(_FINDER_COLUMN_USERID_USERID_2);
2531    
2532                                    String sql = query.toString();
2533    
2534                                    Query q = session.createQuery(sql);
2535    
2536                                    QueryPos qPos = QueryPos.getInstance(q);
2537    
2538                                    qPos.add(userId);
2539    
2540                                    count = (Long)q.uniqueResult();
2541                            }
2542                            catch (Exception e) {
2543                                    throw processException(e);
2544                            }
2545                            finally {
2546                                    if (count == null) {
2547                                            count = Long.valueOf(0);
2548                                    }
2549    
2550                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
2551                                            finderArgs, count);
2552    
2553                                    closeSession(session);
2554                            }
2555                    }
2556    
2557                    return count.intValue();
2558            }
2559    
2560            /**
2561             * Counts all the email addresses where companyId = &#63; and classNameId = &#63;.
2562             *
2563             * @param companyId the company id to search with
2564             * @param classNameId the class name id to search with
2565             * @return the number of matching email addresses
2566             * @throws SystemException if a system exception occurred
2567             */
2568            public int countByC_C(long companyId, long classNameId)
2569                    throws SystemException {
2570                    Object[] finderArgs = new Object[] { companyId, classNameId };
2571    
2572                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C,
2573                                    finderArgs, this);
2574    
2575                    if (count == null) {
2576                            Session session = null;
2577    
2578                            try {
2579                                    session = openSession();
2580    
2581                                    StringBundler query = new StringBundler(3);
2582    
2583                                    query.append(_SQL_COUNT_EMAILADDRESS_WHERE);
2584    
2585                                    query.append(_FINDER_COLUMN_C_C_COMPANYID_2);
2586    
2587                                    query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
2588    
2589                                    String sql = query.toString();
2590    
2591                                    Query q = session.createQuery(sql);
2592    
2593                                    QueryPos qPos = QueryPos.getInstance(q);
2594    
2595                                    qPos.add(companyId);
2596    
2597                                    qPos.add(classNameId);
2598    
2599                                    count = (Long)q.uniqueResult();
2600                            }
2601                            catch (Exception e) {
2602                                    throw processException(e);
2603                            }
2604                            finally {
2605                                    if (count == null) {
2606                                            count = Long.valueOf(0);
2607                                    }
2608    
2609                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, finderArgs,
2610                                            count);
2611    
2612                                    closeSession(session);
2613                            }
2614                    }
2615    
2616                    return count.intValue();
2617            }
2618    
2619            /**
2620             * Counts all the email addresses where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
2621             *
2622             * @param companyId the company id to search with
2623             * @param classNameId the class name id to search with
2624             * @param classPK the class p k to search with
2625             * @return the number of matching email addresses
2626             * @throws SystemException if a system exception occurred
2627             */
2628            public int countByC_C_C(long companyId, long classNameId, long classPK)
2629                    throws SystemException {
2630                    Object[] finderArgs = new Object[] { companyId, classNameId, classPK };
2631    
2632                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C_C,
2633                                    finderArgs, this);
2634    
2635                    if (count == null) {
2636                            Session session = null;
2637    
2638                            try {
2639                                    session = openSession();
2640    
2641                                    StringBundler query = new StringBundler(4);
2642    
2643                                    query.append(_SQL_COUNT_EMAILADDRESS_WHERE);
2644    
2645                                    query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
2646    
2647                                    query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
2648    
2649                                    query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
2650    
2651                                    String sql = query.toString();
2652    
2653                                    Query q = session.createQuery(sql);
2654    
2655                                    QueryPos qPos = QueryPos.getInstance(q);
2656    
2657                                    qPos.add(companyId);
2658    
2659                                    qPos.add(classNameId);
2660    
2661                                    qPos.add(classPK);
2662    
2663                                    count = (Long)q.uniqueResult();
2664                            }
2665                            catch (Exception e) {
2666                                    throw processException(e);
2667                            }
2668                            finally {
2669                                    if (count == null) {
2670                                            count = Long.valueOf(0);
2671                                    }
2672    
2673                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_C,
2674                                            finderArgs, count);
2675    
2676                                    closeSession(session);
2677                            }
2678                    }
2679    
2680                    return count.intValue();
2681            }
2682    
2683            /**
2684             * Counts all the email addresses where companyId = &#63; and classNameId = &#63; and classPK = &#63; and primary = &#63;.
2685             *
2686             * @param companyId the company id to search with
2687             * @param classNameId the class name id to search with
2688             * @param classPK the class p k to search with
2689             * @param primary the primary to search with
2690             * @return the number of matching email addresses
2691             * @throws SystemException if a system exception occurred
2692             */
2693            public int countByC_C_C_P(long companyId, long classNameId, long classPK,
2694                    boolean primary) throws SystemException {
2695                    Object[] finderArgs = new Object[] {
2696                                    companyId, classNameId, classPK, primary
2697                            };
2698    
2699                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C_C_P,
2700                                    finderArgs, this);
2701    
2702                    if (count == null) {
2703                            Session session = null;
2704    
2705                            try {
2706                                    session = openSession();
2707    
2708                                    StringBundler query = new StringBundler(5);
2709    
2710                                    query.append(_SQL_COUNT_EMAILADDRESS_WHERE);
2711    
2712                                    query.append(_FINDER_COLUMN_C_C_C_P_COMPANYID_2);
2713    
2714                                    query.append(_FINDER_COLUMN_C_C_C_P_CLASSNAMEID_2);
2715    
2716                                    query.append(_FINDER_COLUMN_C_C_C_P_CLASSPK_2);
2717    
2718                                    query.append(_FINDER_COLUMN_C_C_C_P_PRIMARY_2);
2719    
2720                                    String sql = query.toString();
2721    
2722                                    Query q = session.createQuery(sql);
2723    
2724                                    QueryPos qPos = QueryPos.getInstance(q);
2725    
2726                                    qPos.add(companyId);
2727    
2728                                    qPos.add(classNameId);
2729    
2730                                    qPos.add(classPK);
2731    
2732                                    qPos.add(primary);
2733    
2734                                    count = (Long)q.uniqueResult();
2735                            }
2736                            catch (Exception e) {
2737                                    throw processException(e);
2738                            }
2739                            finally {
2740                                    if (count == null) {
2741                                            count = Long.valueOf(0);
2742                                    }
2743    
2744                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_C_P,
2745                                            finderArgs, count);
2746    
2747                                    closeSession(session);
2748                            }
2749                    }
2750    
2751                    return count.intValue();
2752            }
2753    
2754            /**
2755             * Counts all the email addresses.
2756             *
2757             * @return the number of email addresses
2758             * @throws SystemException if a system exception occurred
2759             */
2760            public int countAll() throws SystemException {
2761                    Object[] finderArgs = new Object[0];
2762    
2763                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2764                                    finderArgs, this);
2765    
2766                    if (count == null) {
2767                            Session session = null;
2768    
2769                            try {
2770                                    session = openSession();
2771    
2772                                    Query q = session.createQuery(_SQL_COUNT_EMAILADDRESS);
2773    
2774                                    count = (Long)q.uniqueResult();
2775                            }
2776                            catch (Exception e) {
2777                                    throw processException(e);
2778                            }
2779                            finally {
2780                                    if (count == null) {
2781                                            count = Long.valueOf(0);
2782                                    }
2783    
2784                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
2785                                            count);
2786    
2787                                    closeSession(session);
2788                            }
2789                    }
2790    
2791                    return count.intValue();
2792            }
2793    
2794            /**
2795             * Initializes the email address persistence.
2796             */
2797            public void afterPropertiesSet() {
2798                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2799                                            com.liferay.portal.util.PropsUtil.get(
2800                                                    "value.object.listener.com.liferay.portal.model.EmailAddress")));
2801    
2802                    if (listenerClassNames.length > 0) {
2803                            try {
2804                                    List<ModelListener<EmailAddress>> listenersList = new ArrayList<ModelListener<EmailAddress>>();
2805    
2806                                    for (String listenerClassName : listenerClassNames) {
2807                                            listenersList.add((ModelListener<EmailAddress>)InstanceFactory.newInstance(
2808                                                            listenerClassName));
2809                                    }
2810    
2811                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2812                            }
2813                            catch (Exception e) {
2814                                    _log.error(e);
2815                            }
2816                    }
2817            }
2818    
2819            @BeanReference(type = AccountPersistence.class)
2820            protected AccountPersistence accountPersistence;
2821            @BeanReference(type = AddressPersistence.class)
2822            protected AddressPersistence addressPersistence;
2823            @BeanReference(type = BrowserTrackerPersistence.class)
2824            protected BrowserTrackerPersistence browserTrackerPersistence;
2825            @BeanReference(type = ClassNamePersistence.class)
2826            protected ClassNamePersistence classNamePersistence;
2827            @BeanReference(type = ClusterGroupPersistence.class)
2828            protected ClusterGroupPersistence clusterGroupPersistence;
2829            @BeanReference(type = CompanyPersistence.class)
2830            protected CompanyPersistence companyPersistence;
2831            @BeanReference(type = ContactPersistence.class)
2832            protected ContactPersistence contactPersistence;
2833            @BeanReference(type = CountryPersistence.class)
2834            protected CountryPersistence countryPersistence;
2835            @BeanReference(type = EmailAddressPersistence.class)
2836            protected EmailAddressPersistence emailAddressPersistence;
2837            @BeanReference(type = GroupPersistence.class)
2838            protected GroupPersistence groupPersistence;
2839            @BeanReference(type = ImagePersistence.class)
2840            protected ImagePersistence imagePersistence;
2841            @BeanReference(type = LayoutPersistence.class)
2842            protected LayoutPersistence layoutPersistence;
2843            @BeanReference(type = LayoutPrototypePersistence.class)
2844            protected LayoutPrototypePersistence layoutPrototypePersistence;
2845            @BeanReference(type = LayoutSetPersistence.class)
2846            protected LayoutSetPersistence layoutSetPersistence;
2847            @BeanReference(type = LayoutSetPrototypePersistence.class)
2848            protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
2849            @BeanReference(type = ListTypePersistence.class)
2850            protected ListTypePersistence listTypePersistence;
2851            @BeanReference(type = LockPersistence.class)
2852            protected LockPersistence lockPersistence;
2853            @BeanReference(type = MembershipRequestPersistence.class)
2854            protected MembershipRequestPersistence membershipRequestPersistence;
2855            @BeanReference(type = OrganizationPersistence.class)
2856            protected OrganizationPersistence organizationPersistence;
2857            @BeanReference(type = OrgGroupPermissionPersistence.class)
2858            protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
2859            @BeanReference(type = OrgGroupRolePersistence.class)
2860            protected OrgGroupRolePersistence orgGroupRolePersistence;
2861            @BeanReference(type = OrgLaborPersistence.class)
2862            protected OrgLaborPersistence orgLaborPersistence;
2863            @BeanReference(type = PasswordPolicyPersistence.class)
2864            protected PasswordPolicyPersistence passwordPolicyPersistence;
2865            @BeanReference(type = PasswordPolicyRelPersistence.class)
2866            protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
2867            @BeanReference(type = PasswordTrackerPersistence.class)
2868            protected PasswordTrackerPersistence passwordTrackerPersistence;
2869            @BeanReference(type = PermissionPersistence.class)
2870            protected PermissionPersistence permissionPersistence;
2871            @BeanReference(type = PhonePersistence.class)
2872            protected PhonePersistence phonePersistence;
2873            @BeanReference(type = PluginSettingPersistence.class)
2874            protected PluginSettingPersistence pluginSettingPersistence;
2875            @BeanReference(type = PortletPersistence.class)
2876            protected PortletPersistence portletPersistence;
2877            @BeanReference(type = PortletItemPersistence.class)
2878            protected PortletItemPersistence portletItemPersistence;
2879            @BeanReference(type = PortletPreferencesPersistence.class)
2880            protected PortletPreferencesPersistence portletPreferencesPersistence;
2881            @BeanReference(type = RegionPersistence.class)
2882            protected RegionPersistence regionPersistence;
2883            @BeanReference(type = ReleasePersistence.class)
2884            protected ReleasePersistence releasePersistence;
2885            @BeanReference(type = ResourcePersistence.class)
2886            protected ResourcePersistence resourcePersistence;
2887            @BeanReference(type = ResourceActionPersistence.class)
2888            protected ResourceActionPersistence resourceActionPersistence;
2889            @BeanReference(type = ResourceCodePersistence.class)
2890            protected ResourceCodePersistence resourceCodePersistence;
2891            @BeanReference(type = ResourcePermissionPersistence.class)
2892            protected ResourcePermissionPersistence resourcePermissionPersistence;
2893            @BeanReference(type = RolePersistence.class)
2894            protected RolePersistence rolePersistence;
2895            @BeanReference(type = ServiceComponentPersistence.class)
2896            protected ServiceComponentPersistence serviceComponentPersistence;
2897            @BeanReference(type = ShardPersistence.class)
2898            protected ShardPersistence shardPersistence;
2899            @BeanReference(type = SubscriptionPersistence.class)
2900            protected SubscriptionPersistence subscriptionPersistence;
2901            @BeanReference(type = TicketPersistence.class)
2902            protected TicketPersistence ticketPersistence;
2903            @BeanReference(type = TeamPersistence.class)
2904            protected TeamPersistence teamPersistence;
2905            @BeanReference(type = UserPersistence.class)
2906            protected UserPersistence userPersistence;
2907            @BeanReference(type = UserGroupPersistence.class)
2908            protected UserGroupPersistence userGroupPersistence;
2909            @BeanReference(type = UserGroupGroupRolePersistence.class)
2910            protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
2911            @BeanReference(type = UserGroupRolePersistence.class)
2912            protected UserGroupRolePersistence userGroupRolePersistence;
2913            @BeanReference(type = UserIdMapperPersistence.class)
2914            protected UserIdMapperPersistence userIdMapperPersistence;
2915            @BeanReference(type = UserTrackerPersistence.class)
2916            protected UserTrackerPersistence userTrackerPersistence;
2917            @BeanReference(type = UserTrackerPathPersistence.class)
2918            protected UserTrackerPathPersistence userTrackerPathPersistence;
2919            @BeanReference(type = WebDAVPropsPersistence.class)
2920            protected WebDAVPropsPersistence webDAVPropsPersistence;
2921            @BeanReference(type = WebsitePersistence.class)
2922            protected WebsitePersistence websitePersistence;
2923            @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
2924            protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
2925            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
2926            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
2927            private static final String _SQL_SELECT_EMAILADDRESS = "SELECT emailAddress FROM EmailAddress emailAddress";
2928            private static final String _SQL_SELECT_EMAILADDRESS_WHERE = "SELECT emailAddress FROM EmailAddress emailAddress WHERE ";
2929            private static final String _SQL_COUNT_EMAILADDRESS = "SELECT COUNT(emailAddress) FROM EmailAddress emailAddress";
2930            private static final String _SQL_COUNT_EMAILADDRESS_WHERE = "SELECT COUNT(emailAddress) FROM EmailAddress emailAddress WHERE ";
2931            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "emailAddress.companyId = ?";
2932            private static final String _FINDER_COLUMN_USERID_USERID_2 = "emailAddress.userId = ?";
2933            private static final String _FINDER_COLUMN_C_C_COMPANYID_2 = "emailAddress.companyId = ? AND ";
2934            private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "emailAddress.classNameId = ?";
2935            private static final String _FINDER_COLUMN_C_C_C_COMPANYID_2 = "emailAddress.companyId = ? AND ";
2936            private static final String _FINDER_COLUMN_C_C_C_CLASSNAMEID_2 = "emailAddress.classNameId = ? AND ";
2937            private static final String _FINDER_COLUMN_C_C_C_CLASSPK_2 = "emailAddress.classPK = ?";
2938            private static final String _FINDER_COLUMN_C_C_C_P_COMPANYID_2 = "emailAddress.companyId = ? AND ";
2939            private static final String _FINDER_COLUMN_C_C_C_P_CLASSNAMEID_2 = "emailAddress.classNameId = ? AND ";
2940            private static final String _FINDER_COLUMN_C_C_C_P_CLASSPK_2 = "emailAddress.classPK = ? AND ";
2941            private static final String _FINDER_COLUMN_C_C_C_P_PRIMARY_2 = "emailAddress.primary = ?";
2942            private static final String _ORDER_BY_ENTITY_ALIAS = "emailAddress.";
2943            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No EmailAddress exists with the primary key ";
2944            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No EmailAddress exists with the key {";
2945            private static Log _log = LogFactoryUtil.getLog(EmailAddressPersistenceImpl.class);
2946    }