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