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