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