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