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