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