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