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