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