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