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